PHP Runtime Environment: Windows Server R2 VL (Aliyun-qingdao) + PHP5.4.44 + MYSQL 5.6 + IIS8.5 + URL Rewrite 2.0 + FastCGI
Server EXE Runtime Environment: Windows Server R2 VL (Aliyun-qingdao) + E language 5.3
function Send ($in) {try{$socket = socket_create (Af_inet, Sock_stream, sol_tcp); Socket_set_option ($socket, Sol_socket, So_rcvtimeo, Array ("SEC" = 5, "usec" = 0)); Socket_set_option ($socket, Sol_socket, So_sndtimeo, Array ("SEC" = "USec" (0)); $result = Socket_connect ($socket, ' 127.0.0.1 ', 9999); $out = ""; Socket_write ($socket, $in, strlen ($i n); $out = Socket_read ($socket, 10240); Socket_close ($socket); return $out;} catch (Exception $e) {exit ("");}}
This is my code, normal use, before the Trycatch statement, will cause, if a visitor opens this page, another visitor also opens this page, the second user will be reported 500 server error, after some great God post found that the link server failed to cause, But my server EXE does not limit the number of connections, and the first can connect the second how can not be? Is it possible for a php-cgi.exe process to initiate only one socket connection at a time?
Add: The first user opened the Web page has started the socket but did not close the connection, the second user to access the page and create a socket, the second user connection failed error.
All errors are hints at the line where the Socket_connect statement is located.
Reply to discussion (solution)
How did you start the program as a server?
Now that you have the exception handling, you should not hide the exception information
Error message should also be given when an error occurs
This is the basis for judging the wrong reason, don't you think?
You echo down your exception message, or use Socket_strerror (Socket_last_error ($socket)) to output the error generated by the socket
Server-side program is EXE AH of course, directly double-click Ah, I did not make system services ... The exception information returned by PHP is unexpected error on Socket_connect in line 5. The connection failed, all unexpected ... Where should Socket_strerror (Socket_last_error ($socket)) be placed?
How did you start the program as a server?
Now that you have the exception handling, you should not hide the exception information
Error message should also be given when an error occurs
This is the basis for judging the wrong reason, don't you think?
The server-side program is EXE directly double-clicked to start without the Write system service entry. In addition, I did not do unusual treatment, which was added later, ignoring it.
function Send ($in) { $socket = socket_create (Af_inet, Sock_stream, sol_tcp); Socket_set_option ($socket, Sol_socket, So_rcvtimeo, Array ("SEC" = 5, "usec" and "= 0)"); Socket_set_option ($socket, Sol_socket, So_sndtimeo, Array ("SEC" = +, "usec" = 0)); $result = Socket_connect ($socket, ' 127.0.0.1 ', 9999); $out = ""; Socket_write ($socket, $in, strlen ($in)); $out = Socket_read ($socket, 10240); Socket_close ($socket); return $out;}
You echo down your exception message, or use Socket_strerror (Socket_last_error ($socket)) to output the error generated by the socket
The exception message returned by PHP is unexpected error on Socket_connect in line 5
You echo down your exception message, or use Socket_strerror (Socket_last_error ($socket)) to output the error generated by the socket
The exception message returned by PHP is unexpected error on Socket_connect in line 5
if ($result = = False) echo socket_strerror (Socket_last_error ($socket));
if ($result = = False) echo socket_strerror (Socket_last_error ($socket));
Well, no, it's settled. Thank you.
if ($result = = False) echo socket_strerror (Socket_last_error ($socket));
Well, no, it's settled. Thank you.
Share the next experience, everyone learn