|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-17 10:14 UTC] ryosuke_i_628 at yahoo dot co dot jp
Description:
------------
CURLOPT_READFUNCTION waits $fp readable only once.
Is this a bug? Or by design?
Test script:
---------------
<?php
/*
mkfifo /path/to/fifo
*/
$fp = fopen('/path/to/fifo', 'rb');
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'example.com',
CURLOPT_PUT => true,
CURLOPT_INFILE => $fp,
CURLOPT_INFILESIZE => 5,
CURLOPT_READFUNCTION => function ($ch, $fp, $max) {
$buf = fread($fp, 1);
var_dump($buf);
return $buf;
},
]);
curl_exec($ch);
/*
We can verify that CURLOPT_READFUNCTION invocation is blocked.
However, after we executed the following command...
printf "a" > /path/to/fifo
*/
?>
Expected result:
----------------
string(1) "a"
...then invocation should be blocked again
Actual result:
--------------
string(1) "a"
string(0) ""
...wtf!?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 17:00:01 2025 UTC |
This is not related to cURL at all; the same behavior can be observed with the following script: <?php $fp = fopen("/path/to/fifo", 'rb'); var_dump(fread($fp,1)); var_dump(fread($fp,1)); ?> As far as I know, that is norrmal behavior of fifos[1]: | The FIFO must be opened on both ends (reading and writing) | before data can be passed. Normally, opening the FIFO blocks | until the other end is opened also. [1] <https://man7.org/linux/man-pages/man7/fifo.7.html>