stream_set_blocking
reactphp/event-loop
Supported Versions: PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8
Set blocking/non-blocking mode on a stream
Alias
socket_set_blocking
stream_set_blocking
(
resource $stream
,
bool $enable
):
bool
require
__DIR__
.
'/../vendor/autoload.php'
;
if (!
defined
(
'STDIN'
) ||
stream_set_blocking
(
STDIN
,
false
) !==
true
) {
fwrite
(
STDERR
,
'ERROR: Unable to set STDIN non-blocking (not CLI or Windows?)'
.
PHP_EOL
);
exit(
1
);
}
examples/11-consume-stdin.php
if (
$chunk
===
''
) {
Loop
::
removeReadStream
(
$stream
);
stream_set_blocking
(
$stream
,
true
);
fclose
(
$stream
);
return;
}
examples/11-consume-stdin.php
$data
=
str_repeat
(
$data
,
round
(
200000
/
strlen
(
$data
)));
if (!
defined
(
'STDOUT'
) ||
stream_set_blocking
(
STDOUT
,
false
) !==
true
) {
fwrite
(
STDERR
,
'ERROR: Unable to set STDOUT non-blocking (not CLI or Windows?)'
.
PHP_EOL
);
exit(
1
);
}
examples/12-generate-yes.php
if (
$r
===
0
) {
Loop
::
removeWriteStream
(
$stdout
);
fclose
(
$stdout
);
stream_set_blocking
(
$stdout
,
true
);
fwrite
(
STDERR
,
'Stopped because STDOUT closed'
.
PHP_EOL
);
return;
examples/12-generate-yes.php
if (!
$stream
) {
exit(
1
);
}
stream_set_blocking
(
$stream
,
false
);
fwrite
(
$stream
,
"GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n"
);
examples/13-http-client-blocking.php
if (!
$stream
) {
exit(
1
);
}
stream_set_blocking
(
$stream
,
false
);
echo
'Connecting'
;
examples/14-http-client-async.php
if (!
$server
) {
exit(
1
);
}
stream_set_blocking
(
$server
,
false
);
Loop
::
addReadStream
(
$server
, function (
$server
) {
examples/21-http-server.php
public function
testRemoveReadAndWriteStreamFromLoopOnceResourceClosesEndsLoop
()
{
list(
$stream
,
$other
) =
$this
->
createSocketPair
();
stream_set_blocking
(
$stream
,
false
);
stream_set_blocking
(
$other
,
false
);
tests/AbstractLoopTest.php
{
list(
$stream
,
$other
) =
$this
->
createSocketPair
();
stream_set_blocking
(
$stream
,
false
);
stream_set_blocking
(
$other
,
false
);
$this
->
loop
->
addWriteStream
(
$stream
, function () { });
tests/AbstractLoopTest.php
public function
testRemoveReadAndWriteStreamFromLoopOnceResourceClosesOnEndOfFileEndsLoop
()
{
list(
$stream
,
$other
) =
$this
->
createSocketPair
();
stream_set_blocking
(
$stream
,
false
);
stream_set_blocking
(
$other
,
false
);
tests/AbstractLoopTest.php
{
list(
$stream
,
$other
) =
$this
->
createSocketPair
();
stream_set_blocking
(
$stream
,
false
);
stream_set_blocking
(
$other
,
false
);
$this
->
loop
->
addWriteStream
(
$stream
, function () { });
tests/AbstractLoopTest.php
{
list(
$stream
) =
$this
->
createSocketPair
();
stream_set_blocking
(
$stream
,
false
);
$this
->
loop
->
addWriteStream
(
$stream
, function () { });
tests/AbstractLoopTest.php