Inter-script comunication
Moderator: General Moderators
-
nabucodonosor
- Forum Newbie
- Posts: 8
- Joined: Tue Feb 15, 2005 3:22 am
- Location: Verona, Italy
- Contact:
Inter-script comunication
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...
..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...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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.
you can use any standard IPC (named pipes, sockets, signals, shared memory and so on).
Here are selected links to PHP manual chapters:
http://us4.php.net/manual/en/ref.sem.php
http://us4.php.net/manual/en/ref.shmop.php
http://us2.php.net/sockets
http://us2.php.net/manual/en/function.posix-mkfifo.php
http://us2.php.net/manual/en/function.posix-kill.php
Here are selected links to PHP manual chapters:
http://us4.php.net/manual/en/ref.sem.php
http://us4.php.net/manual/en/ref.shmop.php
http://us2.php.net/sockets
http://us2.php.net/manual/en/function.posix-mkfifo.php
http://us2.php.net/manual/en/function.posix-kill.php
-
nabucodonosor
- Forum Newbie
- Posts: 8
- Joined: Tue Feb 15, 2005 3:22 am
- Location: Verona, Italy
- Contact:
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...
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...
-
nabucodonosor
- Forum Newbie
- Posts: 8
- Joined: Tue Feb 15, 2005 3:22 am
- Location: Verona, Italy
- Contact:
Ok,thanks!Weirdan wrote:you can use any standard IPC (named pipes, sockets, signals, shared memory and so on).
Here are selected links to PHP manual chapters:
http://us4.php.net/manual/en/ref.sem.php
http://us4.php.net/manual/en/ref.shmop.php
http://us2.php.net/sockets
http://us2.php.net/manual/en/function.posix-mkfifo.php
http://us2.php.net/manual/en/function.posix-kill.php
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).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....
-
nabucodonosor
- Forum Newbie
- Posts: 8
- Joined: Tue Feb 15, 2005 3:22 am
- Location: Verona, Italy
- Contact:
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!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.
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?
-
nabucodonosor
- Forum Newbie
- Posts: 8
- Joined: Tue Feb 15, 2005 3:22 am
- Location: Verona, Italy
- Contact:
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...
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...
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).