Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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('/var/www/vhosts/httpdocs/chat/chatserver.py',$output);
var_dump($output);

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.

A nice guy was helping me out at SO but couldn't figure out the answer so redirected me to here.

My files are chmod correctly and the function "serverCheck" 100% gets hit but the python script never seems to get executed!

share|improve this question
    
To expand: httpd is running by user apache. User apache is in group chatserver. The py and php files are both 755 and owned by group chatserver. The rest of the comments: stackoverflow.com/questions/15836116/… –  Joe Frambach Apr 5 '13 at 16:01
    
Thank you @JoeFrambach! –  Will Roberts Apr 5 '13 at 16:07
    
What happens when you try to execute the script? Where is your error checking?! –  Michael Hampton Apr 5 '13 at 16:11
    
I get array(0) {} printed out from var_dump($output); and the file doesnt get executed! –  Will Roberts Apr 5 '13 at 16:20
    
What does your apache error log say ? –  etagenklo Apr 6 '13 at 17:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.