Executing a python script from PHP to open a socket -


i have python script chatserver.py includes:-

#!/usr/bin/python twisted.internet.protocol import protocol, factory twisted.internet import reactor <snip> reactor.listentcp(3800, factory) print "server started" reactor.run() 

this opens socket on port 3800 works if start ssh want check open port , if closed reopen using php cannot seem python script execute.

here how calling via php @ 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 lot of things have found on searches cannot seem file execute.

looks permission issue. chatserver.py stands needs root user run it.

don't chmod 777 chatserver.py. dangerous.

the way create group these administrative tasks:

groupadd chatserver 

then add group:

usermod -a -g chatserver willroberts 

then change chatserver.py owned group:

chown root:chatserver chatserver.py 

when php run user, have correct group membership run py file. method allows more flexibility more "chatserver" executables. here's more reading if you're interested: https://wiki.archlinux.org/index.php/users_and_groups , http://www.tldp.org/ldp/intro-linux/html/sect_03_04.html


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -