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