php 致命错误:调用未定义的函数 socket_create()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6137823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:27:46  来源:igfitidea点击:

Fatal error: Call to undefined function socket_create()

php

提问by Sanjeev Kumar Jha

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 )

当我运行创建与 Web 套接字连接的 php 文件时,出现错误 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 .

因此,我无法连接 Web 套接字,也无法从套接字获取响应消息,因为运行客户端页面时,我的浏览器中显示 Socket Status: 3 (Closed)。

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

你知道缺少什么吗?先感谢您。

回答by Jan Han?i?

回答by ambassallo

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.dllto extension=php_sockets.dll.

对于 Windows 上的典型 XAMPP 安装,您的 C:\xampp\php\ext 目录中可能有 php_sockets.dll。所有你要做的就是去为php.ini在C:\ XAMPP \ php目录,并更改;extension=php_sockets.dllextension=php_sockets.dll

回答by Arman H

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.

如果您使用的是 xampp 7.3.9。插座已经安装。您可以检查 xampp\php\ext,您将获得 php_socket.dll。如果你得到它去你的 xampp 控制面板打开 php.ini 文件并从extension=sockets 中删除 (;)

回答by Kiran Maniya

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

php.ini在您的服务器环境中打开该文件并;;extension=sockets. 如果还是不行,就需要下载socketPHP的扩展,放到extphp安装路径下的目录下。重新启动您的 http 服务器,一切都应该正常工作。

回答by Subramanian Sridharan

Follow these steps if you're on openSuse or SUSE.

如果您使用的是 openSuse 或 SUSE,请按照以下步骤操作。

Install php7 if it's not already installed.

如果尚未安装 php7,请安装它。

zypper in php7

If you have php7 installed, update it with:

如果您安装了 php7,请使用以下命令更新它:

zypper update php7

Install php7-sockets

安装 php7-sockets

zypper in php7-sockets

回答by Connor Leech

I got this error when my .envfile was not set up properly. Make sure you have a .envfile with valid database login credentials.

我的.env文件设置不正确时出现此错误。确保您有一个.env包含有效数据库登录凭据的文件。