PHPSocket configuration and instance

Source: Internet
Author: User
2 php test files: server. php? Phpphpinfo (); Ensure that the set_time_limit (0); $ ip127.0.0.1; $ port1935; * + timeout * @ socket communication throughout the process + timeout * @ socket_create * @ socket_ B

2 php test files: server. php? Php // phpinfo (); // ensure that the set_time_limit (0) does not time out when you connect to the client; $ ip = '2017. 0.0.1 '; $ port = 1935;/* + ------------------------------- * @ socket communication throughout the process + ------------------------------- * @ socket_create * @ socket_ B

2 php test files

Server. php

 = 5) {break ;};}// echo $ buf; socket_close ($ msgsock) ;}while (true); socket_close ($ sock);?>


Client. php

 ";}While ($ out = socket_read ($ socket, 8192) {echo" received the server's return message! \ N "; echo" accept the following content: ", $ out;} echo" Close SOCKET... \ n "; socket_close ($ socket); echo" close OK \ n ";?>

Listen
#/Usr/local/php/bin/php/usr/local/apache2/htdocs/server. php

Request

#/Usr/local/php/bin/php/usr/local/apache2/htdocs/client. php

Socket is not enabled in PHP by default.

# Cd./ext/sockets/
#/Usr/local/php/bin/phpize
#./Configure -- enable-sockets -- with-php-config =/usr/local/php/bin/php-config
# Make
# Make install

Php. ini modify configuration

Add

Extension = sockets. so

Restart apache

#/Usr/local/apache2/bin/apachectl restart

==============================

Configuration in Windows

Modify php. ini

Extension = php_sockets.dll

Restart apache

2 under cmd

Php installation directory

C:/php/php.exe F: web/server. php

C:/php/php.exe F: web/client. php

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.