Stream_socket_accept function in cli mode

Source: Internet
Author: User
The stream_socket_accept function in cli mode is edited by jdgdf566 at 17:41:37.

Socket

/* Open a server socket to port 1234 on localhost */$server = stream_socket_server('tcp://127.0.0.1:12345');$socket = stream_socket_accept($server);    /* Grab a packet (1500 is a typical MTU size) of OOB data */    echo "Received Out-Of-Band: '" . stream_socket_recvfrom($socket, 1500, STREAM_OOB) . "'\n";    /* Take a peek at the normal in-band data, but don't comsume it. */    echo "Data: '" . stream_socket_recvfrom($socket, 1500, STREAM_PEEK) . "'\n";    /* Get the exact same packet again, but remove it from the buffer this time. */    echo "Data: '" . stream_socket_recvfrom($socket, 1500) . "'\n";/* Close it up */fclose($socket);fclose($server);

PHP Warning: stream_socket_accept (): accept failed.
This problem does not occur in apache.


Reply to discussion (solution)

Does the firewall allow php?

Does the firewall allow php? Firewall not installed

I don't know. your error message is timeout, or the connection fails.

Check $ errno

I don't know. your error message is timeout, or the connection fails.

Check that $ errno is indeed timeout. When the second parameter of stream_socket_accept ($ server) is 0, it is not an infinite time. This function should be used in the loop structure. The preliminary conclusion is as follows.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.