Page 1 of 1
[SOLVED] ping with exec() gives "Unable to fork"
Posted: Sun May 29, 2005 2:54 am
by mrchiu
I am trying to get the latency of a host with ping using iis6. I am not sure whether or not I have configure the permissions correctly for exec(). But this is the code I am currently using that yields the error.
Code: Select all
<?php
$ping = exec("ping -v google.com");
echo $ping;
?>
Here is where the code is located at.
http://ns1.windermedia.net:81/test/ping.php
Posted: Sun May 29, 2005 4:13 am
by timvw
Afaik, the -v requires you to specify the TOS. It's not the same as on a linux machine
Changed the script to:
Code: Select all
<?php
print_r(`ping google.com`);
?>
Outputted the following:
Code: Select all
Pingen naar google.com ї216.239.57.99] met 32 byte gegevens: Antwoord van 216.239.57.99: bytes=32 tijd=162 ms TTL=236 Antwoord van 216.239.57.99: bytes=32 tijd=161 ms TTL=236 Antwoord van 216.239.57.99: bytes=32 tijd=161 ms TTL=236 Antwoord van 216.239.57.99: bytes=32 tijd=161 ms TTL=236 Ping-statistieken voor 216.239.57.99: Pakketten: verzonden = 4, ontvangen = 4, verloren = 0 (0% verlies).De gemiddelde tijd voor het uitvoeren van ‚‚n bewerking in milliseconden: Minimum = 161ms, Maximum = 162ms, Gemiddelde = 161ms
Posted: Sun May 29, 2005 4:37 am
by mrchiu
woops, I was testing the script on a linux server, forgot to change it back. It is changed now but is still the same.
http://ns1.windermedia.net:81/test/ping.php
I am not sure how you can get an output with
It just prints the string as is.
Posted: Sun May 29, 2005 5:28 am
by timvw
Please notice i used ` instead of '.
Posted: Sun May 29, 2005 5:57 am
by mrchiu
wow, I did not know that is ``, nor did I know it's short for shell_exec, please forgive my ignorance.
New error now.
http://ns1.windermedia.net:81/test/ping.php
Warning: shell_exec(): Unable to execute 'ping google.com' ....
Posted: Mon May 30, 2005 2:55 am
by Chris Corbyn
Wow I never new you could just use backticks to execute system commands

Handy to know.
~mrchiu: What happens if you try that same command from the command line?
Posted: Mon May 30, 2005 3:12 am
by mrchiu
It works fine in the command line.
Posted: Mon May 30, 2005 3:16 am
by timvw
I can only say it works just fine win xp/apache2/php5...
Have been experimenting with php on iis... but it never felt right... and because apache2 was and is running smooth.... i stopped caring about iis...
Posted: Mon May 30, 2005 3:40 am
by mrchiu
Thanks for pointing me in the right direction again.

. I have managed to get it working! I had to give the web service account access to the command line, cmd.exe.
My original code works as well.
I would use apache if I could but the servers that the site will be on uses iis and can't be changed.
Thanks again!