Bug #72864 [Opn->Fbk]: FIFOs block only once
| From: | cmb@php.net | Date: | Tue, 22 Jun 2021 13:54:37 +0000 |
| Subject: | Bug #72864 [Opn->Fbk]: FIFOs block only once | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234586@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72864&edit=1
ID: 72864
Updated by: cmb@php.net
Reported by: ryosuke_i_628 at yahoo dot co dot jp
-Summary: CURLOPT_READFUNCTION waits $fp readable only once.
+Summary: FIFOs block only once
-Status: Open
+Status: Feedback
Type: Bug
-Package: cURL related
+Package: Streams related
Operating System: OSX 10.11.5
PHP Version: 7.0.9
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2016-08-17 10:22:49] ryosuke_i_628 at yahoo dot co dot jp
Note that:
- cURL actually sends "Content-Length: 5"
- Additional printf calls after the first call are completely ignored
------------------------------------------------------------------------
[2016-08-17 10:14:08] 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!?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72864&edit=1