downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

stream_set_timeout> <stream_select
Last updated: Fri, 13 Nov 2009

view this page in

stream_set_blocking

(PHP 4 >= 4.3.0, PHP 5)

stream_set_blockingストリームのブロックモードを有効にする / 解除する

説明

bool stream_set_blocking ( resource $stream , int $mode )

stream のモードをブロックあるいは非ブロックに設定します。

この関数は、非ブロックモードをサポートするすべてのストリーム (現在は、通常のファイルストリームとソケットストリームのみ) において利用可能です。

パラメータ

stream

ストリーム。

mode

mode が 0 の時、ストリームは 非ブロックモードに切り替えられ、1 の場合は、 ブロックモードに切り替えられます。このモードの違いは、 fgets()fread() といった、ストリームからデータを読む関数に影響します。 非ブロックモードにおいては fgets() を呼び出すと どんな場合でもただちに呼び出し元に戻りますが、フロッグモードの場合では、 ストリームがデータを読み出せる状態になるまで待ちつづけます。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

変更履歴

バージョン 説明
4.3.0 PHP 4.3.0 より前のバージョンでは、この関数はソケットベースのストリーム上でのみ動作します。

注意

注意: この関数は以前は set_socket_blocking() という名前で後に socket_set_blocking() に変わりましたが、 この使用法は廃止されました。

参考

  • stream_select() - select() システムコールと同等の操作を、 ストリームの配列に対して tv_sec と tv_usec で指定されたタイムアウト時間をもって行う


stream_set_timeout> <stream_select
Last updated: Fri, 13 Nov 2009
 
add a note add a note User Contributed Notes
stream_set_blocking
galvao at galvao dot eti dot br
16-Dec-2006 01:58
Please notice that this function will not work as for PHP 5.2.0 at least on Win32 systems. It probably won't work on Linux boxes either.

PHP just ignores the function and blocking remains active.

For more information take a look at Bug #36918.
MagicalTux at ookoo dot org
08-Sep-2006 03:13
When you use fwrite() on a non-blocking stream, data isn't discarded silently as t dot starling said.

Remember that fwrite() returns an int, and this int represents the amount of data really written to the stream. So, if you see that fwrite() returns less than the amount of written data, it means you'll have to call fwrite() again in the future to write the remaining amount of data.

You can use stream_select() to wait for the stream to be available for writing, then continue writing data to the stream.

Non-blocking streams are useful as you can have more than one non-blocking stream, and wait for them to be available for writing.
t dot starling at physics dot unimelb dot edu dot au
08-Sep-2005 08:02
Warning: if you write too much data to a stream in non-blocking mode and fill the buffer, the excess will be silently discarded. Observed in PHP 4.4.0 under linux.

stream_set_timeout> <stream_select
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites