January 7th, 2013, 08:09 PM
Controling a python console from php?
I am trying to write a single user, intranet only PHP control panel for my 3d printer using pronterface's pronsole.py interface - it is just a command line, takes commands from stdin, writes to stdout. I thought to use proc_open, but then if the user closes the page, I would have to terminate the process(not what the user wants) OR leave it running and loose the i/o streams(not desirable because then I cant allow the user to regain control). Sessions are not an option because this site will only allow one job at a time due to hardware limitations, and i would like it to be controllable from any computer. I don't know if PHP likes to read/write file pointers to databases or files, but I assume not. What is the best way to do this? Should i just give up on using pronsole and write my own logic that writes to /dev/ttyUSB0? Thanks for help with this vexing problem!
January 7th, 2013, 09:06 PM
Well it's just a Python script. Does it do anything unusual or cryptic or something that would be a hassle to rewrite in PHP?
And so what if the connection closes. Can't you just reconnect?
January 7th, 2013, 09:14 PM
I don't think a rewrite in PHP would be that hard, and it might be required because now that I think about it,reconnecting resets the printer. I actually don't know much about linux device files, but I'm assuming it's possible to write to them discontinuously (if thats the right way to say it), so a rewrite in PHP is probably the way to go, especially for expandability. I was just wondering if there was was simple solution.
January 7th, 2013, 10:26 PM
Depends on the device. If you don't need to adjust port information (baud and the like), or in other words don't need an ioctl() on it, then you can work on the device file just like it were a regular file.
Regardless it sounds like you'll need some kind of spooler: sits in the background waiting for stuff to do. You can't serialize file handles which means you can't put it in a database or save it in the session. And without being particularly careful you can't open it in one script and close it in another either.
January 7th, 2013, 11:09 PM
I will probably write a spooler, the thought of just how easy it could be(I could even integrate it into the python script) just crossed by mind and made this seem like a viable option. Thanks a ton!
Originally Posted by requinix