Create a background process in php -
i working on website want users able create new processes on server , interact server. example, user wants run c code:
#include<sdio.h> int main() { int a; scanf("%d", &a); printf("%d", a); }
in server, create process , keep alive until process stops running. when using functions exec
, cannot scanf
thing. when using proc_open
, cannot keep child process alive.. or can don't know how..
the procedure can be: user sends instruction -> server creates new process instruction -> when doing instruction, server sends stdout
web page , gets stdin
user's input -> process stops running..
i had bespoke chip , pin solution fired off background php cli script using "&" in exec call. front-end , background script communicated passing strings via 2 ascii files. crude effective. both processes had check/read incoming file, decide do(e.g. exeute c++ code on background process), respond if necessary, writing output file. put these 3 steps loop , have crude listener/daemon. further complicated background job having simultaneously listen socket communication channel authorisation service. single user scenario adapted multi-user using unique files or writing keyed database tables.
the call this:
exec ("php mydaemon.php 2>&1>/dev/null &");
i'm assuming linux server - hence linux "&" directive run in background. 2>&1>/dev/null supresses stdout , stderr.
not sure how solve in windows - there must wscript or vbscript equivalent??
Comments
Post a Comment