file_get_contents file_put_contents , , , , fopen. , . , , :)
, fopen http ( , ) . GET ( ), fopen, , HTTP- , . , stream_set_timeout , fopen.
, , fopen; fopen . , stream_context_create ( Sammitch) fopen . , script :
<?php
$ctx = stream_context_create(['http' => [
'timeout' => 1.0,
]]);
$in = fopen('https://reqres.in/api/users?delay=5', 'r', false, $ctx);
$out = STDOUT;
stream_copy_to_stream($in, $out);
var_dump(stream_get_meta_data($in)['timed_out']);
fclose($in);
. , stdout "out", (Darwin). script, .
1, fopen. , .
, - ( ..), fopen . script - , . , , fopen false. , false .
- , .
, script URL. fopen false ().
- , , .
. , script, Content-Length , , ..:
<?php
header('Content-Type: text/plain');
header('Content-Length: 10');
echo "hi";
ob_flush();
sleep(10);
ob_flush PHP ( ) script. , php -S localhost:port, script localhost:port. script , fopen timed_out , true.
stream_set_timeout HTTP GET- fopen , fopen , , . fopen , .