Web Hosting Talk







View Full Version : Network Programming with PHP question


Ileana
05-29-2008, 10:04 AM
In the future I might need to create a script that tallies the domains on a shared IP and pings them..among other things. I was just wondering if this is possible with PHP or do I need to use shell scripting?

sasha
05-29-2008, 10:29 AM
PHP can manipulate raw sockets so yes, you could implement ICMP communication in PHP.

isurus
05-29-2008, 12:16 PM
PHP can manipulate raw sockets so yes, you could implement ICMP communication in PHP.
For example:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=8&txtCodeId=1786

Ileana
05-29-2008, 01:52 PM
Cool thanks!

If you guys know of any good sites with regards to network programming with php please let me know.

Codebird
05-29-2008, 02:24 PM
I think you will need some shell scripting through php though!! not tough scripting but some shell commands

karlkatzke
05-29-2008, 09:40 PM
The sockets API in PHP is pretty much just a direct layer over the C sockets API, so that should be pretty easy to figure out if you're smart enough to be messing with it.

For an easier route, though -- just have PHP make some exec calls to ping or fping. I'd suggest fping.

And if you'd like to avoid this all together -- install Nagios.

Ileana
05-30-2008, 09:20 AM
And if you'd like to avoid this all together -- install Nagios.

Actually that's not a bad idea..

Thanks for the suggestion :)

If for example a client decided to change hosting companies..would it notify of a change in the IP address?

karlkatzke
05-30-2008, 11:34 AM
You can get nagios to do anything. All you need to do is write a plugin (if one doesn't already exist) to watch it and either report "OK" or "WARNING" or "CRITICAL" to standard out. You can write these scripts in PHP, Bash, C, Perl, and pretty much anything else that can, well, output a line of text to standard out.

Ileana
06-02-2008, 01:58 PM
Ohh I like that :D

Thanks for the info, I appreciate it.