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); ?>
Trouble verifying database password
Thankyou to everyone who responded to my last post (I can't find the posting, it has been buried). I am currently making a login form and the associated php code. It all seems to work apart from the
Trouble checking SESSION cookie
I am trying to use $_SESSION cookies to verify admin privileges .I don't understand why this is not working:/*everything above here is working*/ $session = mysql_fetch_array($session_query); $type =
Table trouble
i have been reading the forum for a few weeks and decided to join. i like the format and the advice given is great. anywho here is my table, the issue i have is that i am displaying pictures from
phpMailer will not connect using SMTP
I am trying to use phpMailer with smtp:Code: [Select]$mailer = new PHPMailer();$mailer->IsSMTP();$mailer->Mailer = "smtp";$mailer->SMTPSecure = 'tls';
Sending UDP Raw socket
I truly need help on this. I am trying to write a test program that simulate a network environment that have 5 clients and 1 server. To do so, I need to be able to edit IP header to change it's
gather checkbox data from form into email
Hello all,First, i'd like to thank everyone who responded to my previous posts regarding setting up an SMTP server for my php form. I ended up figuring it out and my form is up and functioning,
Using CSS to format MySQL query
Hi,If i want to have a news page on my site, which displays all records of a table in descending order by date I am using the below code. I can display it all in a big table but this is a bit boring.
Calling variables
I want to call this to my website but it doesn't display what I want it to,Code: <h5>Edit Subject: <?php echo $sel_subject['menu_name']; ?></h5>If I change
Select question
Hi,First I would like to say that php is pretty new for me.. so please don't shoot me if this should be a stupid question!But I'm a little surpized due to following..I have a search script (very large
Mail sending is slow on server
Why mail is taking time to be send on apache-linux server