Bug #80080 [Opn->Fbk]: stream_get_contents is never completed
| From: | cmb@php.net | Date: | Tue, 26 Oct 2021 11:11:38 +0000 |
| Subject: | Bug #80080 [Opn->Fbk]: stream_get_contents is never completed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237379@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80080&edit=1
ID: 80080
Updated by: cmb@php.net
Reported by: clark at electrobeat dot dk
Summary: stream_get_contents is never completed
-Status: Open
+Status: Feedback
Type: Bug
-Package: Sockets related
+Package: Streams related
Operating System: Debian 10
PHP Version: 7.3.22
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Does still still happen to you with any of the actively supported
PHP versions[1]?
If so (which is what I assume), I think you need to make the pipes
non-blocking (stream_set_blocking), and implement a proper
stream_select().
[1] <https://www.php.net/supported-versions.php>
Previous Comments:
------------------------------------------------------------------------
[2020-09-09 09:22:42] clark at electrobeat dot dk
Description:
------------
Sometimes I experience that stream_get_contents never completes executing
In this case a PDF file is processed via poppler's pdftops. The PDF contains some errors though
but when running the command directly in a terminal it completes and returns
The code only prints "opened" but never reach "ouput done"
The PDF can be found here
https://docdro.id/fHlIxBS
Test script:
---------------
$syntax = '/var/bin/poppler-0.79.0/build/utils/pdftops file.pdf file.ps';
$pipes = [];
$process = proc_open($syntax, [
0 => ['pipe', 'r'], // stdin
1 => ['pipe', 'w'], // stdout
2 => ['pipe', 'w'] // stderr
], $pipes);
fclose($pipes[0]);
echo "opened\n";
$output = stream_get_contents($pipes[1]);
echo "output done\n";
$stderr = stream_get_contents($pipes[2]);
echo "err done\n";
foreach($pipes as $pipe){
if(is_resource($pipe)){
fclose($pipe);
}
}
$exitcode = proc_close($process);
echo "err: $stderr\n";
echo "out: $output\n";
Expected result:
----------------
opened
output done
err done
err:
output:
Actual result:
--------------
opened
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80080&edit=1