473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Running php file as a background process

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

Nov 6 '07 #1
8 4754
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 <an*******@freemail.ru>

Nov 6 '07 #2
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.

Nov 6 '07 #3
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.
js*******@attglobal.net
==================

Nov 6 '07 #4
On Nov 6, 1:33 pm, Ravi <Ravindrayep...@gmail.comwrote:
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.

Nov 6 '07 #5
Rob
On Nov 6, 10:12 am, Ravi <Ravindrayep...@gmail.comwrote:
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.

Nov 6 '07 #6
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

Nov 7 '07 #7
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.
js*******@attglobal.net
==================

Nov 7 '07 #8
On Nov 6, 10:12 am, Ravi <Ravindrayep...@gmail.comwrote:
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.

Nov 8 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sticks | last post by:
ok... im not quite sure how to describe my problem. i have a php script that runs through my entire php site and writes the resulting output to html files. this is necessary as the nature of the...
29
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using...
2
by: Anant Raman | last post by:
Hi I have an exe file on my machine. I need to launch this exe from the windows service (written in c#) running on my machine. The service knows about the path where the exe resides. How do I...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
2
by: Dave Hughes | last post by:
Just noticed something rather annoying after upgrading my test box (a Linux server running DB2 UDB v8 for LUW) to fixpak 11 (for reference it was previously on fixpak 7). In the past I've relied...
11
by: news | last post by:
I've a PHP script that does some stuff, zips up some files, and starts an FTP process. I need it to do the Zip and FTP in the background and let the page finish, otherwise the user could have...
5
by: awalter1 | last post by:
Hi, I develop a graphical user interface (with pyGTK) where a click on a button shall launch a program P in background. I want to get the end of this program P but I don't want that my HMI be...
5
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the same...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.