Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Apache 2.2.4 and PHP 5.2.0 Socket Communication Anomaly |
|
Author |
|
pferrara
Joined: 20 Feb 2008 Posts: 1 Location: Frankfort, Illinois
|
Posted: Wed 20 Feb '08 20:52 Post subject: Apache 2.2.4 and PHP 5.2.0 Socket Communication Anomaly |
|
|
I'm relatively new to Apache, PHP, and socket communication, and I'm experiencing some rather bizarre problems with a system I've designed on a local LAN. I have a server running Apache 2.2.4 and PHP 5.2.0, which serves up a control page to multiple users. The server and users are on separate subnets, but are bridged through various network equipment.
My equipment consists of a server, several dozen workstations, and 10 control boxes that sit on their own subnet and receive commands through a socket from the server.
If I start up all the services, the system works fine. After an inconsistent amount of time (40 minutes to 13 hours), several of the devices will stop communicating to the server. Which and what total number of devices that stop responding varies on a case-by-case basis, but it us usually a completely new set of controllers each time. These devices will continue to experience a problem until I either restart the Apache server (usually solves the problem, but not always), or physically unplug the power from the control box and then plug it back in; in the mean-time the majority of the control boxes will continue to properly communicate.
I'm hoping that someone who is more familiar with the nature of socket communication over a LAN, or someone who experienced a similar problem, might be able to shed some light on why some, but not all, of my devices would fail to make a complete bi-directional communication. I am, unfortunately, not very familiar with the way that IP traffic finds its way to a particular device. I know there are a lot of variables that I do not control/am not aware of, but this is all the information that I have at the time. Below are pieces of my socket communication code. Thank you in advance for any help you are able to share.
Code: |
...
$host = SysInfo_GetServerIP();
$port = 5000;
$timeout = 5;
$command = "#COM1[D114,T1,\"RSPW1 \r\"]";
set_time_limit(0);
$nextTime = time() + $gINTERVAL;
$writeOnce = false;
$i=-1;
PrintLine("");
$breakSameLine=false;
while(true)
{
if(time() > $nextTime)
{
//Make sure the system takes at least INTERVAL time between checks
$nextTime+=$gINTERVAL;
$writeOnce = false;
$i++;
if($i>=$myLocCount){ $i=0;}
$remote = $myLoc[$i][4];
$device = "TV@".$remote;
SameLine("Polling device (\"".$device."\"): Connecting...");
//$mysock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
//$isConnected = @socket_connect($mysock,$remote,$port);
$mysock=@fsockopen($remote,$port,$myErr,$myErrStr,$timeout);
//if($isConnected)
if($mysock)
{
SameLine("Polling device (\"".$device."\"): Sending query...");
//socket_write($mysock,$command);
//socket_close($mysock);
fwrite($mysock,$command,strlen($command));
fclose($mysock);
// Create socket, bind socket to port, and send information
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// Listen for response
SameLine("Polling device (\"".$device."\"): Waiting for response...");
$result = socket_listen($socket) or die("Could not set up socket listener\n");
$spawn = false;
$breakSameLine = false;
$myDate = strftime("%A").", ".strftime("%B")." ".strftime("%d");
$myTime = strftime("%H").":".strftime("%M").":".strftime("%S");
switch(@socket_select($r = array($socket), $w = array($socket), $e = array($socket), $timeout-1))
{
case 2:
SameLine("Polling device (\"".$device."\"): Connection to device refused!...");
$breakSameLine = true;
break;
case 1:
SameLine("Polling device (\"".$device."\"): Device responded");
$spawn = socket_accept($socket) or die("Could not accept incoming connection.\n");
break;
case 0:
SameLine("Polling device (\"".$device."\"): Communication with device timed out...");
$breakSameLine = true;
break;
default:
SameLine("Polling device (\"".$device."\"): Unknown communication result...");
$breakSameLine = true;
}
if ($spawn !== false)
{
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$input = trim($input);
socket_close($spawn);
}
// close sockets
socket_close($socket);
}
else
{
SameLine("Polling device (\"".$device."\"): Unable to connect ...");
$breakSameLine = true;
}
//Place a carriage return below the extra line if necessary
if($breakSameLine){ echo "\n";}
if(time() > $nextTime)
{
//Search took to long... increase the interval time
$gINTERVAL*=2;
echo "**!**INCREASING THE SEARCH INTERVAL TIME TO ".$gINTERVAL." SECONDS**!**\n";
$nextTime = time()+floor($gINTERVAL/2);
$breakSameLine=true;
}
//Place another carriage return below the extra line if necessary
if($breakSameLine){ echo "\n";}
...
|
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 02 Apr '08 17:30 Post subject: |
|
|
I think that it is more a network problem than a PHP problem.
Your code it self does not look difficult or havening a long runtime. |
|
Back to top |
|
|
|
|
|
|