Home > Article > Backend Development > What to do if php socket cannot connect
Solution to the problem that php socket cannot connect: 1. Check whether the socket extension is enabled in php; 2. Open the php.ini file and check whether "php_sockets.dll" is loaded; 3. Cancel "php_sockets.dll" Just comment status.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if the php socket cannot be connected?
Solve the problem of failure to connect using php socket
Recently I am using php js to create a multi-person chat function. At first, I wrote the code according to the online steps, but The following error always appears when executing php
Fatal error: Call to undefined function socket_create()
Then I google it again. There are many solutions online, so I will share my success story.
First check whether the socket extension is enabled in php
This is because I did not enable QAQ. . .
if(extension_loaded(‘sockets’)){ echo “已开启”; }else{ echo “未开启”; }
Check the php.ini document under the php installation path again
Pay attention to the version of php used and find the corresponding version. For example, mine:
D:\PHPTutorial\php\php-7.2.1-nts
Check whether php_sockets.dll is loaded
Pay attention to whether this line of code is commented. (Mine is in the comment state)
If it is in the comment state, just remove the comment~~
Recommended Study: "PHP Video Tutorial"
The above is the detailed content of What to do if php socket cannot connect. For more information, please follow other related articles on the PHP Chinese website!