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

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

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.

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.

Seems like permission error,
Try,
chmod -R folder_to_be_file_written
Then execute php script

Related

modbus(watlow F4T) allow to be connected, but does not allow to be read

the mobus (watlow F4T) allows for connection, my pc use a static IP and watlow F4T is also using a static IP(192.168.0.222), it works well on another laptop or pc, but it could not work on one windows 7 laptop.
The modbus use a 502 port and I checked firewall, and using telnet 192.168.0.222 502 there is no error message, if I use a different port the telnet returns a connection failure, so I assume port 502 is open.
I use ModbusTcpTest130 to test, same setting, when I try to read something from watlow F4T, it always mentions "unable to do modbus read, please check the port setting", as different laptop would work, so I assume there is something special on this laptop, anybody has clue?
update: I tried another pc, it works when I only use modbusTCP130, however, when I tried modbus poll (I forgot to close modbusTCP130 connection), it fails, then after close both modbus poll and modbustcp130, whatever I use modbusTCP130 or modbuspoll, both fail, so looks port not released?
How you are closing the port?. Just closing down the terminal?
When you are not sure that your port is closed, I would suggest rebout devices on both ends. Also make sure there are only one instance of terminal is running.
It wort to try change communication port on device to different one, to make sure that, on PC that port is not being use with diff applications.

socket.py not creating listener on server

I set variables host and port instead of setting the 'address' variable tuple in socket.py. I was unable to get 'address' as a tuple to work. I do not believe this is the issue, but I thought I should state this up front.
FYI, my goal is an integrations project, and I believe I isolated socket.py as the problematic code. socket.py is not creating a listener on the remote server. I run the python script on my client, and my server address is 192.168.1.130 port 7879.
I think socket.py is the problem, because I do not receive the expected print statements back through the console that socket.py is attempting to create a socket. In addition, I can RDC to the server, disable ufw (yes I know this is a bad idea), create a tcp listener, push data through the client socket to the server socket, and verify this with netcat.
Am I mistaken that I should be able to parameterize socket.py with nothing more than a host and port and be able to create a socket connection? I am happy to provide more detail from logs, but I thought I should start with a very high level overview.
Answer: More investigation needed. I think socket.py does not create the remote connection with socket(),bind(),listen() statements; instead simply looks for a listener on the remote server with a connect() statement. This is entirely my misunderstanding given I did not dive into the details of the socket.py code. I figured this out because the service running on the remote server creates the listener, but the service itself on the remote server is what is not properly starting.

Port is open on localhost but remote host reports closed port

I am trying to setup a pptp server on Centos,
I open port 1723 (pptp port) with no issues when setting up pptp, and I do a nmap scan to confirm that it is open, however when I nmap the server remotely, it doesnt even list port 1723, by which I assume that port 1723 is not accesable
Is there something I am missing, forgetting
p.s., my first time setting up, so I am noob, please forgive any mistakes or missunderstandings and please dont down vote, I really need help and posting on serverfault apparently is of topic for this too...
UPDATE after #Calvin
Thank you for your informative response, do you know of anyway I can check where it is being blocked???
It is probably being blocked by a proxy server/firewall that the remote request has to go through. So for example, you're in one location A, wanting to connect to the other location B (which you've said is setup correctly and open to requests), though the security apparatus at location A have blocked outgoing requests to whatever port range, and likely outside your control unless you know the network administrators to check with them.
Is my first assumption.

Sockets on a webhost

If you telnet to the ip address 192.43.244.18 port 13, you'll get the current time.
well, if I'm not wrong, this is simply a server socket. But there's one thing strange: how's this socket always listening?
If I take a PHP page and program sockets in there, I still have to request for the page first in order to activate the server socket, but this one isn't associated with any pages, and even if a make a perl script, I still have to request for that in order to run the server socket!
My question is: how can I make such a thing - an always listening socket - on a webhost (any language will do)?
You can run the process that's listening on the socket as a daemon (Linux) or service (Windows), or just a regular program really (although that's less elegant).
A simple place to begin would be http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html which teaches you how to make a simple serversocket in Java that listens for a connection on a specific port. The program created will have to be run at all times to be able to accept the connections.

How do online port checkers work?

For example http://www.utorrent.com/testport?port=12345
How does this work? Can the server side script attempt to open a socket?
There are many ways of accomplishing this through server-side scripting. As #Oded mentioned, most server-side handlers are capable of initiating socket connections on arbitrary ports, and most of those even have dedicated port-scanning packages/libraries (PHP has one in the PEAR repository, Python's 'socket' module makes this type of tasks a breeze, etc...)
Keep in mind that on shared host platforms, socket connections are typically disabled for security purposes.
Another way that is also very easy to accomplish is to use a command-line port-scanner such as nmap from your server-side script. i.e in PHP, you would do echo ``nmap -p $port $ip\
The server side script will try to open a connection on the specified port to the originating IP.
If there is no response (the attempt will timeout), this would be an indication that the port is not open.
The server can try, as #Oded said. But that doesn't ensure the receiver will respond.
Typically, something like this happens:
The URL request contains instructions about which port to access. The headers that your browser sends include information about where the request is originating from.
Before responding to the request, the server tries to open a port and checks if this is successful. It waits a while before timing out.
The webpage is rendered dynamically based on the results of this test.
The response is returned to you containing the results.
Sometimes steps (2) and (3) will be replaced with an AJAX callback, which allows the response to return sooner.