php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52918 fpassthru causes early script termination with no errors
Submitted: 2010-09-23 22:21 UTC Modified: 2010-09-24 03:43 UTC
From: ray at rainstormconsulting dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.2.14 OS: CentOS 4.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ray at rainstormconsulting dot com
New email:
PHP Version: OS:

 

 [2010-09-23 22:21 UTC] ray at rainstormconsulting dot com
Description:
------------
I am using PHP 5.2.14 built from source on CentOS 4.8. This also happens in PHP 
5.2.13.

Basically what is happening is that if I run the following code (from a web 
address, not CLI), and terminate before sleep() is done performing, I do not see 
the last error_log(). I only see the one before fpassthru(). This only happens 
when $content is very large (not sure how large, but my script was using ~15MB 
string).

It appears that if I add ob_start() and ob_end_flush() around the script, 
everything performs correctly, even if I terminate the script early.

I have already verified that the content is in fact being written to $file just 
fine. I manually checked the file and also called file_get_contents() after 
file_put_contents() and the data came back just fine.

Again, I receive no errors in the PHP error log or Apache log (e.g. no 
segfaults).

Test script:
---------------
// $content must be much larger than this sample...something like 15MB of base64
// encoded data will do the trick.
$content = 'JVBERi0xLjQKJeTjz9IKNjMgMCBvYmoKPDwKL0xpbmVhcm';

file_put_contents($file, $content); // $file is a valid full file path/name

$fp = fopen($file, 'r');

sleep(5); // This is only here to aid in terminating the script before fpassthru() is called.

error_log('Error log before fpassthru() is called!');
$characterCount = fpassthru($fp);
error_log(var_export($characterCount, true));

Expected result:
----------------
I would expect fpassthru() to not totally kill the script. Even though the client 
will not see the contents of fpassthru(), the rest of the script should still 
perform as expected.

Actual result:
--------------
The script terminates before the last error_log is called and no errors are 
displayed, no segfaults reported, etc., even when the highest PHP error logging is 
enabled.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-24 03:43 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-09-24 03:43 UTC] cataphract@php.net
This is expected behavior. See ignore_user_abort. Using buffering delays sending the data, hence delaying the moment PHP is able to detect the connection's been aborted.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 01:01:28 2024 UTC