Ping in parallel

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
vaerge2
Forum Newbie
Posts: 3
Joined: Fri Jul 09, 2010 4:53 pm

Ping in parallel

Post by vaerge2 »

Hi,

I have some PHP code that fetches a list of IP addresses from a database, it then pings these IPs, saves results to a file, retrieves the 'cleaned' result from the file and writes the info to a database. So far so good. But then I ran into trouble...
Let's say that I do five pings with one second between each one - and I want to do that once per minute. That's not a problem when i have less than 12 IP addresses to ping. The problem is that the code is waiting for the ping to one IP to finish before it can start the next one - and that is five seconds for each ping. So if there are 15 IPs, then that's 75 seconds - and I am unable to repeat the ping every minute for each IP address.

How do I handle this? Any ideas? (hoping not to hear that I need some complicated async stuff!).

thanks!

//Anders
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Ping in parallel

Post by Jade »

If you don't want to use ajax or something similar then I would suggest creating multiple files and running them at the same time (not really a great solution, I would probably pick a different language like c/c++ that can spawn multiple threads). Have each file "lock" the IP when it starts the ping process so each file will know which IP address are currently in progress or completed.

Ohh, also I did a search on php and threading and found this that may be useful to you: http://www.alternateinterior.com/2007/0 ... n-php.html
Post Reply