fwrite() not permitted, but phpinfo() says it should be

◇◆丶佛笑我妖孽 提交于 2019-12-12 13:58:47

问题


I am getting the following from a script I am trying to run:

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

However, when I check phpinfo(), allow_url_fopen is on and Sockets Support is Enabled. I haven't been able to find anything pointing me to what might be causing this.

For clarification, I did not write this script. My knowledge of PHP is mostly just the basics, but I know enough to reason that this should be working since phpinfo() says the correct things are permitted. The script in question is here: https://github.com/xPaw/PHP-Minecraft-Query/blob/master/MinecraftQuery.class.php


回答1:


fwrite() writes to $this->socket and is in private function WriteData(). In public function Connect() is a line

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

This is the only line in this file where $this->socket is written.

Also, there is a warning message in the 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.

This is probably the case. The socket is created although the ip adddress or the port is not reachable. This results in an error message when trying to write data.

So in order to resolve this, you would need to do at least these things:

  • Make sure the ip address and port are correct.
  • Verify that the server is up and running.
  • Make sure the ip address and port are reachable (not blocked in any firewalls)

I do not know what the correct settings should be. If you have installed the software on an external server, also try your local computer so you have a way to verify the ip address and port settings.




回答2:


If you checked your PHP configuration and the problem persists, check your firewall log.

As Ignacio Vazquez-Abrams stated: this is an OS error.

In my case, CSF was blocking outgoing connections.




回答3:


Seems like permission error,

Try,

 chmod -R folder_to_be_file_written

Then execute php script



来源:https://stackoverflow.com/questions/12152706/fwrite-not-permitted-but-phpinfo-says-it-should-be

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!