Hello,
Earlier I posted about my problem with my socket script. It took up to 100% CPU usage.
Now I found the problem. With another found simple PHP socket script, I saw it has the same problem.
The code of this basic script is as follows:
I placed echo's to see what is happening.
When I execute the script, and connect using for example Windows Telnet to the socket, it connects without a problem. When I just CLOSE the telnetbox while connected, I see a loop of the POS7 message.
Then the CPU usage is exeeding, I think this is my problem.
Does anybody know how to fix this, that when someone just connects and closes the session, there is no loop?
Line number On/Off | Expand/Contract <? set_time_limit(0);ob_implicit_flush();$address = '0.0.0.0';$port = 5010;if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "n";}if (socket_bind($sock, $address, $port) === false) { echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "n";}if (socket_listen($sock, 5) === false) { echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "n";}echo "pos1n";do {echo "pos2n"; if (($msgsock = socket_accept($sock)) === false) { echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "n"; break;echo "pos3n"; }do { $out = socket_read($msgsock, 2048); if (!empty($out)) { if ($out == 'quit') { break; }elseif ($out == 'shutdown') { socket_write($msgsock, 'plc down', 8); socket_close($msgsock); break 2; }else { switch ($out) { case "A": $response = "A!"; break; case "B": $response = "B!"; break; default: $response = "C!";echo "pos4n"; } socket_write($msgsock, $response, strlen($response)); break;echo "pos5n"; }echo "pos6n"; }echo "pos7n"; } while (true);echo "pos8n"; socket_close($msgsock);} while (true);echo "pos9n";socket_close($sock); ?>
please hep to get values from a table row
can anyone tel me how I can select and get data from one row by pressing an Edit button in that row?<?phpif (!empty($avil_holidays)){ foreach ($avil_holidays as $val) { switch
Force download script not handling files with spaces properly
I have a regular old php force download script, uses this code:Code: header("Cache-Control: "); header("Pragma: "); header("Content-type: application/octet-stream");
Lining up columns nicely.
Hello everyone, I'm having problems with making columns line up properly. Here is my code:
PHP Error
On my .php page I have a drop down box that has several names in it. When a user clicks the name & fills the rest of the form out, an email is sent to a supervisor. It works great EXCEPT, if I
double and single quotes in text fields acting up... help please
Single quotes, when entered into a text field, create an sql error upon Submit. It seems to create the query OK but says there's an SQL syntax error and stalls out on that field.Also any time a
Strange PHP/mySQL error ... am I just tired?
Code: <?## CONNECT TO DB FUNCTION!function ConnectTo($db2con){ $hostName = "localhost"; $dbName = "people_".$db2con; $userName = "people_main"; $password =
How to limit the calls to an API
Hello, in my simple script I call an api which effectively involves me getting an xml file.However the problem is everytime I get a visitor to the webpage it calls the API which means lots of wasteful
Hashing?
Hi, I was hoping to take a string value then convert it - consistently - across each of our pages into a alphanumeric value. I figured the hash function would be able to accomplish this; the results
Need help making a blockquote and line items conditional
I have some code I bought a few years ago that allows my clients to update content on their site using an Excel spreadsheet. Well this particular application sometimes has line items so I need to come
help with Get_
ok some how this is not working i am not sure what i am doing wrong here but what this does is when the user goes to Secret-Codes.php they get a menu and when they pick the phone they want to view it