php script consuming CPU-usage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lnp80
Forum Newbie
Posts: 7
Joined: Thu Mar 31, 2005 1:26 pm

php script consuming CPU-usage

Post by lnp80 »

Hello

(using Windows XP)
I am running a php-script and during execution it is starting another php-script (myPHP_script.php). This second php-script is running in the background and everything is working fine when i start the initial php-script from the command line. The problem starts when i try to run the php-script with Explorer or some other web-browsers -> the system then begin using a total of 100% CPU. I have tried to start "calc.exe" instead of "php myPHP_script.php" and then everything seems to be ok.

Code: Select all

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("php myPHP_script.php", 3, false);
I do not know what might be wrong and i would be wery pleased if anyone could help me solve this.

PS. I have also tried to use shell_exec() but the same problem occured. And in adition i didn't manage to use shell_exec() for having a process running in the background.

regards
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Post us the code from myPHP_script.php.... sounds like some kind a infinite loop issue :?
lnp80
Forum Newbie
Posts: 7
Joined: Thu Mar 31, 2005 1:26 pm

myPHP_script.php

Post by lnp80 »

myPHP_script.php

my php-script doesnt do anything else than echo'ing 'Hello'. The script is supposed be continously checking some weather data, but when a simple hello halts the initial script i havent started on this. Have also tried to run a python script from the initial php-script but the result is the same.
My code is simply:

Code: Select all

echo 'hello';
I am not able to run any php or python scripts from the initiating php-script. But .exe files are ok. Also all, php, python and .exe are ok if the initiating php-script is started from the shell. The problem occurs when i run the initiating php-script from a web-browser!


User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hmmm... try

Code: Select all

oExec = $WshShell->Run("php.exe -f myPHP_script.php", 3, false);
lnp80
Forum Newbie
Posts: 7
Joined: Thu Mar 31, 2005 1:26 pm

the 'php -f myPHP_script.php' didnt help

Post by lnp80 »

hello again

the '-f' didnt help, but i forgot to tell that what i am making is a web page residing in an apache server. From this page i want to start another php-script. Maybe the problem is the path. My apache-server'root is in 'web'

initiator code:

Code: Select all

<?
$sep = DIRECTORY_SEPARATOR;
$WshShell = new COM("WScript.Shell");
$path = "C:".$sep."web".$sep."komponenter".$sep."testfiler".$sep;
$cmd = "php -f ".$path."myPHP_script.php";
$oExec = $WshShell->Run($cmd, 3, false);
?>
myPHP_script code:

Code: Select all

<?
$fd = fopen("foo.txt", "w");
$dateTime = date("Y-m-d H:i:s ", strtotime("now"));
fputs($fd, "Hallo: ".$dateTime);
fclose($fd);
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Do you have the php installation folder correctly added to the path environament variable in windows so that you can just call php.exe without giving a full path? - Also... you say CPU hits 100%... but does the script ever execute?
lnp80
Forum Newbie
Posts: 7
Joined: Thu Mar 31, 2005 1:26 pm

i think it is some path problem

Post by lnp80 »

the environment-variable is set, I just use php (not the whole path).
I do think that the path I am using will not be correct from the apachservers point of view, since everything is working when i'm running it locally from my terminal.

But I don't know what other path I should use... The apache root is 'C:\web', and the files resides in 'C:\web\komponents'

And you are right, the script does not execute. I guess it is not found?
Post Reply