check network connection

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
Homesick
Forum Newbie
Posts: 16
Joined: Tue Apr 06, 2010 1:53 am

check network connection

Post by Homesick »

Hi guys ,,
I want to write on a file if the local server connection is down ,,
So,,I wanna ask if there a script to check the network connection of the local server,,
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: check network connection

Post by cpetercarter »

I have seen a number of scripts where fsockopen() is used to test whether a connection with a remote website could be established, and I guess that you could use it also for a connection to a local server.

Or you could simply use whatever script you use to write your file to the server, using the fact that fopen() returns 'false' if the file concerned cannot be opened (for whatever reason) :

Code: Select all

$h = @fopen($server_file, 'wb');
if (!$h) {
// write to the local machine instead
}
Post Reply