Socket problem
Posted on
16th Feb 2014 07:03 pm by
admin
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.
Did you know?Explore Trending and Topic pages for more stories like this.
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); ?>
No comments posted yet
Your Answer:
Login to answer
65
31
Other forums
Error in SQL Syntax HELP!!!
I have this page:
Code: <?php
session_start();
//connect to server and s
Parse multirow HTML table
Hello all,
I have a site I am working on. Its a sports site and I am trying to add stats to a DB
form help
this doesn't work. i want the form action to go the location.href of the submit button chosen.. how
Is there a quick way to do this?
Hi all,
I need to create a mysql table from php that goes a little something like this
need help in mysql_num_rows()
please tell me what i am doing wrong in this query. it displays this error
Code: Warning: mys
Storing/displaying image urls in a database?
Hi
Basically I have the following scenario:
User chooses picture from list. Picture info is ad
start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get
Mail sending is slow on server
Why mail is taking time to be send on apache-linux server
Displaying image pathname instead of image
Hello
Im trying to upload and then display images from a mysql database - Its only basic and
How do I replace any number of character occurences with one occurrence?
How do I replace any number of character occurences with one occurrence?
Let's say I have: