php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72864 FIFOs block only once
Submitted: 2016-08-17 10:14 UTC Modified: 2021-07-04 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ryosuke_i_628 at yahoo dot co dot jp Assigned: cmb (profile)
Status: No Feedback Package: Streams related
PHP Version: 7.0.9 OS: OSX 10.11.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ryosuke_i_628 at yahoo dot co dot jp
New email:
PHP Version: OS:

 

 [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!?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-17 10:22 UTC] 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
 [2021-06-22 13:54 UTC] cmb@php.net
-Summary: CURLOPT_READFUNCTION waits $fp readable only once. +Summary: FIFOs block only once -Status: Open +Status: Feedback -Package: cURL related +Package: Streams related -Assigned To: +Assigned To: cmb
 [2021-06-22 13:54 UTC] cmb@php.net
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>
 [2021-07-04 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 05:01:29 2024 UTC