fwrite()不允许,但是phpinfo()表示应该

我从尝试运行的脚本中获取以下信息:

Notice: fwrite() [function.fwrite]: send of 7 bytes failed with errno=1 Operation not permitted in /home/thrawn/public_html/sorcero.us/MinecraftQuery.class.php on line 165

但是,当我检查phpinfo()时,allow_url_fopen已打开,并且套接字支持已启用.我一直找不到任何指向我的原因.

为了澄清起见,我没有编写此脚本.我对PHP的了解大多只是基础知识,但是我知道足够多的理由认为这应该可行,因为phpinfo()表示允许正确的操作.有问题的脚本在这里:https://github.com/xPaw/PHP-Minecraft-Query/blob/master/MinecraftQuery.class.php

解决方法:

fwrite()写入$this->套接字,并且位于私有函数WriteData()中.在公共函数Connect()中是一行

$this->Socket = @FSockOpen( 'udp://' . $Ip, (int)$Port, $ErrNo, $ErrStr, $Timeout );

这是该文件中唯一写入$this-> socket的行.

另外,在manpage for fsockopen()中有一条警告消息

UDP sockets will sometimes appear to have opened without an error,
even if the remote host is unreachable. The error will only become
apparent when you read or write data to/from the socket. The reason
for this is because UDP is a “connectionless” protocol, which means
that the operating system does not try to establish a link for the
socket until it actually needs to send or receive data.

可能是这种情况.尽管无法找到ip地址或端口,但已创建套接字.尝试写入数据时,这会导致错误消息.

因此,为了解决此问题,您至少需要执行以下操作:

>确保IP地址和端口正确.
>确认服务器已启动并正在运行.
>确保IP地址和端口可访问(在任何防火墙中均未阻止)

我不知道正确的设置应该是什么.如果您已在外部服务器上安装了该软件,也请尝试在本地计算机上使用,以便您可以验证IP地址和端口设置.

上一篇:PHP fwrite() 函数


下一篇:php;使用fgetcsv和SplFileObject :: fseek;读行问题