Page 1 of 1
Inter-script comunication
Posted: Tue Feb 15, 2005 11:13 am
by nabucodonosor
I'm not shure if I'm writing in the right forum...
..I have a question (maybe ingenuo):
is it possible to have more than one php script running on the server, and accessing eachother functions,variables,objects and so on?
I need to have a php program running indefinitely in background on the web server (as a "thread"). It should be able to passa and recieve data to the other php scripts that ar called by the web server in response of the web clients activity.
Thanks to anyone who can clear my doubts...
Posted: Tue Feb 15, 2005 11:31 am
by feyd
in short, no.
in long.. possibly. You probably have to create your own a channel between the background script and the client visible ones. It shouldn't be a database.
What is this background script doing? Most hosts will not allow scripts to run indefinitely, as most will eat a processor in doing so.
Posted: Tue Feb 15, 2005 11:38 am
by Weirdan
Posted: Tue Feb 15, 2005 11:45 am
by nabucodonosor
Thanks for replay!!!
In poor words:
the "background" script should act as a driver/monitor for a serial controller... it accepts new "write requests" to the resource and listens for fresh data coming from the resource.
Any remote client (web browser) asks the fresh data and the web server, after interrogating the "driver" script, returns the page with requested data... I thought that the better way, but the solutions are still open...
Posted: Tue Feb 15, 2005 11:51 am
by nabucodonosor
Ok,thanks!
In fact I knew that there's always the soket solution (if I'm in win32 environment I can't use the shared memory at all...wright?) but I didn't know in prectise how to "fork" a script running in background in apache and acting as a server for the secceding scripts....
Posted: Tue Feb 15, 2005 11:57 am
by feyd
so it's a live poll of the serial connection? no pooling or anything like that? Then it doesn't need a background script. What about creating an extension to php? This way, you can write a faster processing system in C for example, and a simple interface through php.
Posted: Tue Feb 15, 2005 12:28 pm
by Weirdan
nabucodonosor wrote:
In fact I knew that there's always the soket solution (if I'm in win32 environment I can't use the shared memory at all...wright?) but I didn't know in prectise how to "fork" a script running in background in apache and acting as a server for the secceding scripts....
Some kind of exec (
http://php.net/exec) should do the trick... or you could run your background script as a service (using srvany.exe from Windows Resource Kit).
Posted: Tue Feb 15, 2005 12:32 pm
by nabucodonosor
feyd wrote:so it's a live poll of the serial connection? no pooling or anything like that? Then it doesn't need a background script. What about creating an extension to php? This way, you can write a faster processing system in C for example, and a simple interface through php.
Do you mean to register a new wrapper for example?Mmh, that's very fashinating! But I think it's too much for me,I don't know where to begin from!
I thought also to write a C application, but I'm not practical with the IPC and not shure of there's interoperability between a php script and a C application. Because the serial device refreshes, for example, a variable every 2 seconds we could think about a global variable accessible by the script and the process... but if I would mantain the portability on win32 I can't use the shared memory, and the posix functions too...or not?
At last, there's always the possibility, in a php script, to open a soket to a certain process (a C application...). But the question is: is it possible to open a socket to another php script running on the same server?
Posted: Tue Feb 15, 2005 12:38 pm
by feyd
nabucodonosor wrote:But the question is: is it possible to open a socket to another php script running on the same server?
should be possible, but I'd avoid it as much as possible.
Posted: Tue Feb 15, 2005 1:13 pm
by Weirdan
feyd wrote:should be possible, but I'd avoid it as much as possible.
May I ask, why?
Posted: Tue Feb 15, 2005 1:53 pm
by feyd
Weirdan wrote:May I ask, why?
It mostly comes down to personal preference. When dealing with hardware, I personally want all the speed I can get for it. To me, that means a fully compiled binary.
Posted: Tue Feb 15, 2005 4:30 pm
by nabucodonosor
Ok, I think that the most elegant solution should be that with language extension.
But if I choose the soket comunication between 2 php threads (is it an improper terminology?) my banal problem is still operative: how to, inside a php script, launch another php script whose execution will continue separately.
Maybe another approach could be throwing a redirect from the middle of the script, so the actual script continues its own execution...
Posted: Wed Feb 16, 2005 1:02 pm
by Weirdan
It appears it would be better to launch background script (hereafter 'server') separately (e.g. as a winnt service) and have it continuously listen on some tcp port (just like webserver does). Then you may connect to it from any php web apps. This way you don't need to mess with execs (anyway there's no reason to have multiple servers polling the same COM port, IMO).