I’m running exactly the same ping script on two servers. On one server it does die after 3 seconds, on the other it doesn’t die, it just keeps going.
Anyone know what server config/php config I should be looking at to rectify this?
system(“ping -c 3 google.com 2>&1 & sleep 3; kill $!”)
ping -c 3 -w 3 google.com
I assume it’s a php/server configuration issue. Not a code issue?
I have 2 linux servers (from the same hosting company) ones newer than the other. But I can’t for the life of me work out what makes the kill work on one, but not the other?
What happens when you run that command via ssh directly?
I tried on both servers, essentially same response
Displays ping, then (after 3s);
 Terminated ping -c 9 google.com 2>&1
So if it works through SSH, but doesn’t kill through PHP… i’m assuming its a php config issue?
The -w flag sounds like it does what you want without having to bg the process and then sleep and kill. It didn’t work?
I’m not that familiar with unix/shell commands. What does the -w flag mean? And, no it didn’t kill the script after 3.
I asked my hosting company, and they said it’s likely to do with the setup of the server, with fastcgi installed.
Right thanks, I prefer your way then.
With my way, would that mean, if I was running a bunch of ping scripts concurrently, a sleep & kill would effect all other ping scripts working at the same time?
I really doubt it would kill them all. There’s probably a separate instance of the ping program spawned each time you issue that command, and each would have its own process id, so the kill should target the correct one because your shell should know the correct process id.