I've developed a simple streams class to handle get, post and put requests (based on the documentation and user notes here).
The simplest example:
<?php
// a simple GET request:
include('eac_streams.class.php');
$http = new stream();
$result = ('http://www.domain.com/somepage.php');
?>
Along with that, I have a curl class that does nearly the same thing.
http://www.kevinburkholder.com/sw_curl_stream.php
Hope it's useful. Any feedback is welcomed.
Thanks.
[note: cross-posted to curl page]
ストリーム 関数
目次
- stream_bucket_append — bucket を brigade に追加する
- stream_bucket_make_writeable — 操作する brigade から bucket オブジェクトを返す
- stream_bucket_new — 現在のストリームで使用する新しい bucket を作成する
- stream_bucket_prepend — bucket を brigade に追加する
- stream_context_create — ストリームコンテキストを作成する
- stream_context_get_default — デフォルトのストリームコンテキストを取得する
- stream_context_get_options — ストリーム / ラッパ / コンテキストに設定されているオプションを取得する
- stream_context_set_default — デフォルトのストリームコンテキストを設定する
- stream_context_set_option — ストリーム / ラッパ / コンテキストのオプションを設定する
- stream_context_set_params — ストリーム / ラッパ / コンテキストのパラメータを設定する
- stream_copy_to_stream — データをあるストリームから別のストリームにコピーする
- stream_encoding — ストリームのエンコード用の文字セットを設定する
- stream_filter_append — ストリームにフィルタを付加する
- stream_filter_prepend — フィルタをストリームに付加する
- stream_filter_register — php_user_filter に由来するクラスとして実装されたストリームフィルタを登録する
- stream_filter_remove — ストリームからフィルタを取り除く
- stream_get_contents — 残りのストリームを文字列に読み込む
- stream_get_filters — 登録されているフィルタのリストを取得する
- stream_get_line — 指定されたデリミタの位置までのデータを一行分としてストリームから読み込む
- stream_get_meta_data — ヘッダーあるいはメタデータをストリームまたはファイルポインタから取得する
- stream_get_transports — 登録されたソケットのトランスポートの一覧を取得する
- stream_get_wrappers — 登録されているストリームのラッパのリストを取得する
- stream_notification_callback — notification コンテキストパラメータ用のコールバック関数
- stream_register_wrapper — stream_wrapper_register のエイリアス
- stream_resolve_include_path — fopen に相対パスを指定してコールされたときに、 どのファイルをオープンするかを決める
- stream_select — select() システムコールと同等の操作を、 ストリームの配列に対して tv_sec と tv_usec で指定されたタイムアウト時間をもって行う
- stream_set_blocking — ストリームのブロックモードを有効にする / 解除する
- stream_set_timeout — ストリームにタイムアウトを設定する
- stream_set_write_buffer — 指定されたストリームのファイルバッファリングを有効にする
- stream_socket_accept — stream_socket_server で作られたソケットの接続を受け入れる
- stream_socket_client — インターネットドメインまたは Unix ドメインのソケット接続を開く
- stream_socket_enable_crypto — 接続済みのソケットについて暗号化の on/off を切り替える
- stream_socket_get_name — ローカルまたはリモートのソケットの名前を取得する
- stream_socket_pair — 接続された、区別できないソケットストリームの組を作成する
- stream_socket_recvfrom — 接続されているかどうかにかかわらず、ソケットからのデータを受信する
- stream_socket_sendto — 接続されているかどうかにかかわらず、ソケットにデータを送信する
- stream_socket_server — インターネットドメインまたは Unix ドメインのサーバソケットを作成する
- stream_socket_shutdown — 全二重接続を終了する
- stream_wrapper_register — PHP のクラスとして実装された URL ラッパを登録する
- stream_wrapper_restore — 事前に登録を解除された組み込みラッパを復元する
- stream_wrapper_unregister — URL ラッパの登録を解除する
ストリーム 関数
kburkholder at earthasylum dot com
10-Mar-2008 04:43
10-Mar-2008 04:43
marcus at synchromedia dot co dot uk
15-Nov-2007 04:13
15-Nov-2007 04:13
I can't find any real documentation on the quoted-printable-encode stream filter, but I've gathered info from several places. It seems there are 4 options that can be passed in the param array as in my other note on this subject:
line-length: integer, simply sets line length before a soft break is inserted
line-break-chars: Which char or chars to consider as a line break - note that "\r\n" will only match CRLF, not CR or LF, so make sure it matches your content.
binary: boolean, hex encodes all control chars, including spaces and line breaks, but leaves alphanumerics untouched
force-encode-first: Forcibly hex-encodes the first char on each line, even if it's alphanumeric. This is useful for avoiding corruption in some incompetent mail servers, like Exchange.
marcus at synchromedia dot co dot uk
30-Oct-2006 11:16
30-Oct-2006 11:16
As this article says, there is no quoted_printable_encode function() in PHP: http://www.zend.com/manual/filters.convert.php
However there is a stream filter for quoted printable encoding. Here's an example function that produces output suitable for email and doesn't explicitly use external files (though it might do for strings over 2Mb due to the nature of the temp stream type):
<?php
function quoted_printable_encode($string) {
$fp = fopen('php://temp/', 'r+');
$params = array('line-length' => 70, 'line-break-chars' => "\r\n");
stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
fputs($fp, $string);
rewind($fp);
return stream_get_contents($fp);
}
echo quoted_printable_encode(str_repeat("hello there ", 50)." a=1\r\n")."\n";
?>
The filter needs to be restricted to STREAM_FILTER_READ because by default it will get filtered both going into and out of the stream, and will thus get encoded twice.
It should be much faster than using a PHP implementation of the same thing, though note that this will only work in PHP 5.1+.
jausions at php dot net
15-May-2006 09:59
15-May-2006 09:59
For the "notification" index of the $params for stream_context_set_params() function, a callable function is accepted. That is array(&$object, 'methodName') will also work.
