|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18707 Can't run PHP script in background from a PHP CGI script?
Submitted: 2002-08-02 10:18 UTC Modified: 2002-08-02 18:58 UTC
From: scottg at particle dot net Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 4.2.1 OS: Linux 2.2.20
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.
Block user comment
Status: Assign to:
Bug Type:
From: scottg at particle dot net
New email:
PHP Version: OS:


 [2002-08-02 10:18 UTC] scottg at particle dot net
This is the strangest thing in the world and I have no idea why it happens.  I'm using Linux 2.2.20 with PHP 4.2.1.  I have PHP compiled in as a module and I have an external PHP binary for CGI work.  

I want bg.cgi to run in the background.

#!/usr/php/bin/php -q
  system("/usr/php/bin/php -f /somepath/bg.cgi >>/dev/null 2>>/dev/null &"); 
  echo "Ok!\n";

#!/apps/php/bin/php -q
  mail ("", "Test Subject", "Test Message");

I run start.cgi with the brower like a normal cgi script - The web page says Ok! like it should.  In the background now I have a bg.cgi process but its going crazy.  It dies and restarts repeatedly.  It gots on for about 1 minute then gives up.  The process number increases with each new bg.cgi process.  Only one bg.cgi process every exists though.  Strangest thing ever.  I never do get the email message bg.cgi is suspose to send.

If I run start.cgi from the command prompt all is well, only one bg.cgi runs fine and I get the email after 5 seconds.

Anyone know why bg.cgi runs crazy if called like this?

Oh ya, if I had a start.php:
<? system("/apps/php/bin/php -q -f /home/scottg/web/run/bg.cgi >>/dev/null 2>>/dev/null &"); ?>
and just viewied it in the browser so that the php module runs bg.cgi all works fine too.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-02 10:45 UTC]
You should redirect stdin too. The following example returns _immediately_:
system("sleep 10 </dev/null >/dev/null 2>/dev/null &");
 [2002-08-02 11:56 UTC] scottg at particle dot net
Yes, system("sleep 10 </dev/null >/dev/null 2>/dev/null &");
works because your running sleep or another binary executable.

You must run another PHP script in order to see how crazy it gets.  Wether you run

system("/usr/php/bin/php -f /somepath/bg.cgi >>/dev/null 2>>/dev/null &"); 


system("/usr/php/bin/php -f /somepath/bg.cgi </dev/null >/dev/null 2>/dev/null &"); 

It works if bg.cgi is a binary like sleep but will not work if bg.cgi is another PHP script such as:

#!/usr/php/bin/php -q
  mail ("", "Test Subject", "Test Message");

Same thing happens under 4.2.1 and 4.2.2 and probably older versions.
 [2002-08-02 12:18 UTC]
Can't reproduce, but i'm using the CLI binary...
(IIRC, there is another bug similar to this one, where the header output gets repeated almost forever... can't find the bug # anymore)
 [2002-08-02 12:23 UTC]
Ah, #11430! Probably related.
 [2002-08-02 18:58 UTC]
duplicate of: #11430 
Add your comments there..

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 08:01:23 2020 UTC