I have a python script chatserver.py that includes:-
#!/usr/bin/python
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
<SNIP>
reactor.listenTCP(3800, factory)
print "Server Started"
reactor.run()
This opens a socket on port 3800 which works if I start from SSH but I want to do a check for the open port and if it is closed reopen using PHP but I cannot seem to get the python script to execute.
Here is how I am calling it via PHP at the moment
function serverCheck() {
$host = "MYHOST";
$port = 3800;
$connection = @fsockopen($host, $port);
if ( !is_resource($connection) ) { // port not open
exec('/usr/bin/python PATH_TO_FILE/chatserver.py 2>&1');
if($connection)
fclose($connection);
}
I have tried a lot of things I have found on my searches but I just cannot seem to get the file to execute.
.pyfile has the shebang, you don't need to explicitly tell bash to use/usr/bin/python. Justchmod +x chatserver.py{and}are mismatched!!}on yourif.ls -l chatserver.pyshowsroot:root? And I assume you're running the php script asyourname:yourname? That's your problem right there :)