php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80080 stream_get_contents is never completed
Submitted: 2020-09-09 09:22 UTC Modified: 2021-11-07 04:22 UTC
From: clark at electrobeat dot dk Assigned: cmb (profile)
Status: No Feedback Package: Streams related
PHP Version: 7.3.22 OS: Debian 10
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-09-09 09:22 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-26 11:11 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: Sockets related +Package: Streams related -Assigned To: +Assigned To: cmb
 [2021-10-26 11:11 UTC] cmb@php.net
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>
 [2021-11-07 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 Mar 19 02:01:28 2024 UTC