Running php file as a background process
Running php file as a background process
am 06.11.2007 11:12:05 von ravi
Hi to all,
There is a start button in my page. if user clicks on that then a php
program should start and should listen on a particular port. and also
user should able to do other tasks on that page.
Is there any way to run php file as background process. Or is there
any to run multi thread in php.
Regards,
Ravindra.Y
Re: Running php file as a background process
am 06.11.2007 12:36:12 von AnrDaemon
Greetings, Ravi.
In reply to Your message dated Tuesday, November 6, 2007, 13:12:05,
> There is a start button in my page. if user clicks on that then a php
> program should start and should listen on a particular port. and also
> user should able to do other tasks on that page.
> Is there any way to run php file as background process. Or is there
> any to run multi thread in php.
Ask Your hosting company support staff. Running processes as daemons are
denied by most providers.
Otherwise, if it is Your own computer, You're trying to solve problem
backwardly. Why not write script that listen to specific port and keep
it running in background all day?
(Yes, "listen" is a key word to search through manual)
--
Sincerely Yours, AnrDaemon
Re: Running php file as a background process
am 06.11.2007 13:01:38 von Jerry Stuckle
Ravi wrote:
> Hi to all,
>
>
> There is a start button in my page. if user clicks on that then a php
> program should start and should listen on a particular port. and also
> user should able to do other tasks on that page.
>
>
> Is there any way to run php file as background process. Or is there
> any to run multi thread in php.
>
>
>
> Regards,
> Ravindra.Y
>
>
Hi, Ravindra,
You can't multithread in PHP. But if you have the authority, you can
start a PHP task in the background. How to do it depends on your OS.
However, you also have to watch your maximum execution time, or the
process will time out. Again, if you have the authority, you can change
this in your script.
I don't know of any shared hosting which will allow you to do this.
You'll need either a dedicated server or a VPS to do it.
I'm not sure PHP is the correct language to be doing this in, however.
Just what are you trying to do?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Running php file as a background process
am 06.11.2007 13:33:11 von ravi
Hi,
Thanks for replying. Ya this is my own system. But if it listen any
commands then the handler should execute the functions of a
particular object. where object will be created when i start the
process.
The process is like this
1. user presses a start button.
2. Then i should create an object . For exg obj = new A(); where obj
will have the user details.
3. then one program should run background to listen on a port.
4. When it got any response then it should manipulate the object user
data.
5. In the meanwhile user can use the user interface through browser.
If u got any solution plz send me it is very urgent.
Regards,
Ravindra.
Re: Running php file as a background process
am 06.11.2007 14:44:02 von Jerry Stuckle
Ravi wrote:
> Hi,
> Thanks for replying. Ya this is my own system. But if it listen any
> commands then the handler should execute the functions of a
> particular object. where object will be created when i start the
> process.
>
> The process is like this
>
> 1. user presses a start button.
> 2. Then i should create an object . For exg obj = new A(); where obj
> will have the user details.
> 3. then one program should run background to listen on a port.
> 4. When it got any response then it should manipulate the object user
> data.
> 5. In the meanwhile user can use the user interface through browser.
>
> If u got any solution plz send me it is very urgent.
>
>
>
> Regards,
> Ravindra.
>
>
Ravi,
You can do it in PHP, at least on Unix, but it's not going to be easy.
Probably the best way is with shared memory and semaphores.
First of all, you'll need to compile PHP with the --enable-sysvsem flag
to get the shared memory and ipc functions.
You can then create a shared memory segment and use semaphores to
serialize access to the shared memory, or use message queues to send
messages back and forth (or both). Start a process in the background to
handle the socket communications and communicate between it and your web
page.
But there are a lot of problems with this. First of all, HTTP is a
request/response protocol; the server can't just arbitrarily send
information to the browser. The browser has to request it. So if there
is a change in the object's data, this won't be reflected in the user's
browser until they refresh (or do something else). You can get around
this to a certain point with automatically refreshing the page (i.e.
meta refresh or javascript), but there will be a delay.
Also, web pages are transactional - that is, from the server side, the
page loads, executes, sends its data to the client and terminates. So
you need to keep track of your communications methods between pages.
You can use sessions to do this, but you won't be able to keep the
shared memory or message queue itself in the session - just the name.
Something like this isn't real difficult in C/C++ or Java (but it's not
easy, either). However, I really wonder if PHP is a good choice here.
I would think maybe a Java applet on the client and a Java program
running on the server would be better.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Running php file as a background process
am 06.11.2007 17:22:29 von darko
On Nov 6, 1:33 pm, Ravi wrote:
> Hi,
> Thanks for replying. Ya this is my own system. But if it listen any
> commands then the handler should execute the functions of a
> particular object. where object will be created when i start the
> process.
>
> The process is like this
>
> 1. user presses a start button.
> 2. Then i should create an object . For exg obj = new A(); where obj
> will have the user details.
> 3. then one program should run background to listen on a port.
> 4. When it got any response then it should manipulate the object user
> data.
> 5. In the meanwhile user can use the user interface through browser.
>
> If u got any solution plz send me it is very urgent.
>
> Regards,
> Ravindra.
Consider what you were already advised - a daemon program resident in
memory all the time, not on user request. You can also consider using
AJAX on the client side, since going away from the page is equal to
losing every connection with the server for a moment, which is enough
for the server to "forget" about your client, unless some form of
"key" is included in the cookies etc. by which the server can
recognize the client from before.
I think, however, that if you're in a "hurry", that you better
reconsider the whole thing.
Re: Running php file as a background process
am 06.11.2007 17:48:46 von Rob
On Nov 6, 10:12 am, Ravi wrote:
> Hi to all,
>
> There is a start button in my page. if user clicks on that then a php
> program should start and should listen on a particular port. and also
> user should able to do other tasks on that page.
>
> Is there any way to run php file as background process. Or is there
> any to run multi thread in php.
>
> Regards,
> Ravindra.Y
Depending on the Operating System, I would use exec() to submit a
'cron' job running a php script to listen to the port.
I would then use a file or database to communicate between the two
applications.
If you are running Windows, you can use 'schtask' instead of cron, but
it depends if your host allows O/S commands or not.
Rob.
Re: Running php file as a background process
am 06.11.2007 18:48:10 von Bucky Kaufman
"Ravi" wrote in message
news:1194343925.644364.209200@v29g2000prd.googlegroups.com.. .
> Hi to all,
>
> There is a start button in my page. if user clicks on that then a php
> program should start and should listen on a particular port. and also
> user should able to do other tasks on that page.
>
> Is there any way to run php file as background process. Or is there
> any to run multi thread in php.
It sounds like you're a skilled programmer... but in some other language.
So this should help:
You can't run a PHP page as a true "background process"... anymore than you
can Javascript or VBScript.
To do what you (vaguely) described, you probably need to create your process
as a client-side program, either as an ActiveX/Java applett or as a (perhaps
hidden) pop-up web page.
Re: Running php file as a background process
am 07.11.2007 09:54:19 von ravi
Thank you guys for all u r replys.
let me say one thing that after initiating the process i need not to
display it in browser.Actually i am using it to communicate with
Asterisk server.
Initiated process by the user will have some phone no [may be in
thousands] my program should able to repeat the the loop to make
calls. Then when the call connected then Asterisk will raise some
events on one port where i should listen it. After completion of calls
the listening program should stop. Where i am thinking that is it
possible to bind these 2 things into one class to avoid db connection.
I know these things can be done in C++ or Java but all my project is
done in PHP where this is a simple module in that. I appreciate if
anybody advises me something.
Regards,
Ravindr.Y
Re: Running php file as a background process
am 07.11.2007 13:58:13 von Jerry Stuckle
Ravi wrote:
> Thank you guys for all u r replys.
>
>
> let me say one thing that after initiating the process i need not to
> display it in browser.Actually i am using it to communicate with
> Asterisk server.
>
> Initiated process by the user will have some phone no [may be in
> thousands] my program should able to repeat the the loop to make
> calls. Then when the call connected then Asterisk will raise some
> events on one port where i should listen it. After completion of calls
> the listening program should stop. Where i am thinking that is it
> possible to bind these 2 things into one class to avoid db connection.
>
> I know these things can be done in C++ or Java but all my project is
> done in PHP where this is a simple module in that. I appreciate if
> anybody advises me something.
>
> Regards,
> Ravindr.Y
>
>
Ravi,
Maybe the rest of your project is being done in PHP, but that doesn't
mean PHP is the best piece for this. You're going to run into a lot of
problems.
I don't know why you don't want to use a database. That would be a
logical way to handle things.
I think you should reexamine your approach to this piece.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Running php file as a background process
am 08.11.2007 18:00:13 von jamesgoode
On Nov 6, 10:12 am, Ravi wrote:
> Hi to all,
>
> There is a start button in my page. if user clicks on that then a php
> program should start and should listen on a particular port. and also
> user should able to do other tasks on that page.
>
> Is there any way to run php file as background process. Or is there
> any to run multi thread in php.
>
> Regards,
> Ravindra.Y
Hi Ravi,
Although it may be possible to write a TCP server with PHP, I would
not recommend it. If it's just a simple server you're trying to
write, try using a better-suited language if possible. I would
recommend Ruby, it is excellent for network programming, and it has
good string and file handling.
Hope this helps,
-James.