[SOLVED] ping with exec() gives "Unable to fork"

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
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

[SOLVED] ping with exec() gives "Unable to fork"

Post 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
Last edited by mrchiu on Mon May 30, 2005 3:41 am, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 &#1111;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
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post 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

Code: Select all

print_r('ping google.com');
It just prints the string as is.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Please notice i used ` instead of '.
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post 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' ....
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

It works fine in the command line.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

Thanks for pointing me in the right direction again. :D . 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. :D

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!
Post Reply