开发者

PHP script is executing multiple times when only invoked once on the command line. Only output of first run is sent to stdout

开发者 https://www.devze.com 2023-01-30 16:02 出处:网络
Everytime I invoke a PHP script via the command line in windows (either in cygwin or cmd) the script seems to be running multiple (6) times, however only the output of the first run is sent to the scr

Everytime I invoke a PHP script via the command line in windows (either in cygwin or cmd) the script seems to be running multiple (6) times, however only the output of the first run is sent to the screen's output. It's a very weird problem, a little tricky to describe.

test.php:

<?php
$t = microtime();
error_log($t . "\n", 3, 'test.out');
echo $t;
?>

I run the script once, and this is the result

$ php test.php;
0.97800300 1292476780
$ cat test.out
0.97800300 1292476780
0.04000200 1292476781
0.09500200 1292476781
0.14700200 1292476781
0.19900200 1292476781
0.25600300 1292476781

Across different test files, and different versions of PHP, it seems to consistently run 6 times. It Doesn't matter if I run the script through cygwin or the windows shell. I've Tried using php5.2.6 and php5.2.7 and php5.2.11 - all installed via WAMP. I tried using strace, but its output was blank - I've never used it on windows before, perhaps my cygwin installation isn't correct. I'm using windows 7, and the problem started when I started using windows 7. I have a colleague running windows 7 and he has the exact same problem, however everyone (including my former self) running windows xp has no problem at all with the php CLI.

I hope I'm not missing anything obvious here! Let me know anyt开发者_运维知识库hing else I can provide, and if anyone has any ideas or advice I would be most grateful!


It's indeed really weird... Try this

<?php
$t = microtime();
file_put_contents('test.out', $t);
echo $t;
?>


So it now looks like an error in the versions/builds of PHP I'm using, as testing with different versions of PHP will not produce the same error. I clearly made an error in my above post (and testing yesterday) and didn't correctly test with the different versions.

Updated test.php

<?php
$t = microtime();
error_log($t."\n", 3, $argv[1]);
echo $t;
?>

And running with 5.2.6, 5.2.7 and 5.2.11

Paul@Paul-Macbook-W7 ~
$ /cygdrive/c/wamp/bin/php/php5.2.6/php test.php test-526.out
0.20960200 1292539753
Paul@Paul-Macbook-W7 ~
$ cat test-526.out
0.20960200 1292539753
0.27060200 1292539753
0.32160200 1292539753
0.37460200 1292539753
0.42460200 1292539753
0.47660200 1292539753

Paul@Paul-Macbook-W7 ~
$ /cygdrive/c/wamp/bin/php/php5.2.7/php test.php test-527.out
0.32660200 1292539767
Paul@Paul-Macbook-W7 ~
$ cat test-527.out
0.32660200 1292539767

Paul@Paul-Macbook-W7 ~
$ /cygdrive/c/wamp/bin/php/php5.2.11/php test.php test-5211.out
0.70760500 1292539776
Paul@Paul-Macbook-W7 ~
$ cat test-5211.out
0.70760500 1292539776

So I guess at this stage I can only conclude it's a bug in the php build I've got for 5.2.6: PHP 5.2.6 (cli) (built: May 2 2008 18:02:07)

0

精彩评论

暂无评论...
验证码 换一张
取 消