Re: exec() and redirect output of program
| From: | Tijnema ! | Date: | Tue, 01 May 2007 19:04:31 +0000 |
| Subject: | Re: exec() and redirect output of program | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254202@lists.php.net to get a copy of this message | ||
On 5/1/07, Brad Fuller <bfuller@cpacampaigns.com> wrote:
Brad Fuller wrote: Daniel Brown wrote:It seems that the php binary isn't the same version as the php library used in the webserver and so that there's a problem loading Zend. Are you sure that the PHP binary is also replaced when they reinstalled PHP? TijnemaIt seems the script is calling itself even though I'm specifying a different script to run... test2.php <?php echo "Hello, World!"; ?> test1.php <?phpThis way just lets it do it's own thing, with no output, and PHPwon't hang. It'll continue from the CLI after the HTTP session is over. <? exec('php test.php > /dev/null 2>&1 &'); ?> On 5/1/07, Brad Fuller <bfuller@cpacampaigns.com> wrote:I found this on PHP.net: http://us.php.net/manual/en/function.exec.php Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends. This is what I want... I want to execute another PHP script from the CLI, pass it a parameter and let it go to town after the HTTP request closes. Can someone please illustrate how I can make this work? Thx, Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpif( !isset($_POST['account_id']) ||$_POST['account_id'] == "" ) {echo "account_id is required."; exit; }// more stuff here...exec("/usr/bin/php -q /path/to/test2.php", $output); // should runtest2.phpecho "<pre>"; print_r($output); echo "</pre>";http://www.example.com/test1.php Expected Result: Array ([0] => Hello, World!) Actual Result: Array ([0] => X-Powered-By: PHP/5.2.1 [1] => Content-type: text/html [2] => [3] => account_id is required.) Can anyone explain this and possibly help me find a solution? Thx, Brad P.S. I am posting a form to the test1.php page with a valid account_id etc.; after re-reading the message I thought someone might think it's printing that result because nothing is posted. Update: I also found a file called "error_log" in the folder where test2.php resides, full of several of these lines: [01-May-2007 14:12:52] PHP Warning: Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0 Could that have something to do with why the script is calling on itself instead of running the specified php script? I recently had the hosting company rebuild PHP, first they did --enable-suexec (to run PHP as CGI) and then later rebuilt again to --enable-pcntl and --enable-sigchild, as I thought I would be needing that functionality. Did that break the CLI? Please help, Thx. Brad