Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to undefined function socket_create()

Tags:

php

My code is like this:

if( ($this->master=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0 )

    {
    die("socket_create() failed, reason: ".socket_strerror($this->master));
    }

when I run my php file which create connection with web socket, I got error Fatal error: Call to undefined function socket_create() in the line if( ($this->master=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0 )

Therefore i am not able to connect web socket and also not able to get response message from socket because Socket Status: 3 (Closed) is displaying in my browser when run client page .

Have you got an idea what is missing? Thank you in advance.

like image 794
Sanjeev Kumar Jha Avatar asked May 26 '11 11:05

Sanjeev Kumar Jha


4 Answers

You'll need to install (or enable) the Socket PHP extension: http://www.php.net/manual/en/sockets.installation.php

like image 161
Jan Hančič Avatar answered Nov 08 '22 12:11

Jan Hančič


For a typical XAMPP install on windows you probably have the php_sockets.dll in your C:\xampp\php\ext directory. All you got to do is go to php.ini in the C:\xampp\php directory and change the ;extension=php_sockets.dll to extension=php_sockets.dll.

like image 45
ambassallo Avatar answered Nov 08 '22 11:11

ambassallo


If you are using xampp 7.3.9. socket already installed. You can check xampp\php\ext and you will get the php_socket.dll. if you get it go to your xampp control panel open php.ini file and remove (;) from extension=sockets.

like image 10
Arman H Avatar answered Nov 08 '22 10:11

Arman H


Open the php.ini file in your server environment and remove ; from ;extension=sockets. if it's doesn't work, you have to download the socket extension for PHP and put it into ext directory in the php installation path. Restart your http server and everything should work.

like image 5
Kiran Maniya Avatar answered Nov 08 '22 10:11

Kiran Maniya