472,989 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Have PHP start a background thread/process

Hi All,

I am working on a mailing list program for a client, and I am wondering
what tbe hest way to deal with script timeouts is. I realize that I
could use set_time_limit() to increase the script timeout, but that
doesn't handle situations where 1) safe mode is on, or 2) Apache's
timeout is exceeded. These mailings go out to between 5000 and 10000
email addresses, so timeouts are a concern.

It seems to me that the best thing to do would be to fire off a separate
process, perhaps a PHP script that runs directly via the php executable
(a command line script, rather than a .php file that is executed through
Apache).

Is there a way to trigger a process that will then run on its own? The
PHP script running in the browser could then send a message saying
"delivery started" or something, and the separate PHP script that has
been fired would handle the actually delivery. It would run outside of
Apache, and can record success/failure in a database.

Running PHP4.3.9 on RHEL (but I would like a solution that is not tied
to a particular version of PHP or Linux, if possible).

Thoughts?

Sincerely,
-Josh
Jul 17 '05 #1
5 18067
Hi,

I've done a similar solution (in perl though). Have the browser script
update a database/text/config file.

Have a scheduler (cron on unix, at on windows) execute the script that
will do the background work only after checking the value updated by the
browser script and have it clear it after finishing the job.

I had it every 3 hours and used a text file, depends on tipe of job and
you can have it run up to every minute.

Hope to have helped ;-)
Jul 17 '05 #2
Joshua Beall wrote:
Hi All,

I am working on a mailing list program for a client, and I am wondering
what tbe hest way to deal with script timeouts is. I realize that I
could use set_time_limit() to increase the script timeout, but that
doesn't handle situations where 1) safe mode is on, or 2) Apache's
timeout is exceeded. These mailings go out to between 5000 and 10000
email addresses, so timeouts are a concern.
A way to manage the timeout could be to generate a small output say after each
100 mails sent (echo ".";), this would keep the page alive for the apache
server. But, no I don't think this is the best option this time.

It seems to me that the best thing to do would be to fire off a separate
process, perhaps a PHP script that runs directly via the php executable
(a command line script, rather than a .php file that is executed through
Apache).

Is there a way to trigger a process that will then run on its own? The
PHP script running in the browser could then send a message saying
"delivery started" or something, and the separate PHP script that has
been fired would handle the actually delivery. It would run outside of
Apache, and can record success/failure in a database.

Running PHP4.3.9 on RHEL (but I would like a solution that is not tied
to a particular version of PHP or Linux, if possible).


You could try something like system('php script.php &');
Not sure if that will work in the same way in php as it does in shell.

//Aho
Jul 17 '05 #3
Joshua Beall wrote:

Is there a way to trigger a process that will then run on its own? The
PHP script running in the browser could then send a message saying
"delivery started" or something, and the separate PHP script that has
been fired would handle the actually delivery. It would run outside of
Apache, and can record success/failure in a database.

Running PHP4.3.9 on RHEL (but I would like a solution that is not tied
to a particular version of PHP or Linux, if possible).


The only solutions I know of are:

1) run a daemon process to control the background process and initiate it
from your PHP (rather complicated)

2) start a process which forks and resets it's process group. (afaik
impossible using PHP only)

3) `at now 'php -q background.php'`

HTH

C.
Jul 17 '05 #4
J.O. Aho wrote:
You could try something like system('php script.php &');
Not sure if that will work in the same way in php as it does in shell.


It works exactly the same way; although both processes run concurrently, the
parent process will wait for the child to terminate. See post in
alt.comp.lang.php

C.
Jul 17 '05 #5
DH
Joshua Beall wrote:
Hi All,

I am working on a mailing list program for a client, and I am wondering
what tbe hest way to deal with script timeouts is. I realize that I
could use set_time_limit() to increase the script timeout, but that
doesn't handle situations where 1) safe mode is on, or 2) Apache's
timeout is exceeded. These mailings go out to between 5000 and 10000
email addresses, so timeouts are a concern.

It seems to me that the best thing to do would be to fire off a separate
process, perhaps a PHP script that runs directly via the php executable
(a command line script, rather than a .php file that is executed through
Apache).

Is there a way to trigger a process that will then run on its own? The
PHP script running in the browser could then send a message saying
"delivery started" or something, and the separate PHP script that has
been fired would handle the actually delivery. It would run outside of
Apache, and can record success/failure in a database.

Running PHP4.3.9 on RHEL (but I would like a solution that is not tied
to a particular version of PHP or Linux, if possible).

Thoughts?

Sincerely,
-Josh

Possibly a cron job running a PHP script that writes and subsequently
reads its own a log file ... containing the settings for the next SQL
query's start row and limit.

http://www.phpfreaks.com/tutorials/28/0.php
Jul 17 '05 #6

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

Similar topics

1
by: Sin Jeong-hun | last post by:
Many applications need to lanch a web browser to show its homepage to users. I used System.Diagnosis.Process.Start("http://www.google.com"); Or I launched other application like...
6
by: HK guy | last post by:
If i call another process to run, how to run as background.? Thank you.
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
0
by: henning.friese | last post by:
Hello NG, I'm need to write some code which creates tiff files from various document types (doc, pdf, xls). I want to do this by ShellExecuting (via System.Diagnostics.Process) the doc-files...
3
by: JN | last post by:
Hello, I am trying to write a program or service that will run in the background and wait for a particular program to start, when it does I want something else to occur such as a message box. I...
3
by: tshad | last post by:
I created a service in VS 2003 and the code works fine as an application, but not as a service. It installs fine, but when I try to start it, it tells me it was unable to start. Am I missing...
16
by: Thirsty Traveler | last post by:
I would like to create a test harness that simulates multiple concurrent users executing an individual thread. I would like this to be determined at runtime when the user specifies the number of...
33
by: bonk | last post by:
I have an application that needs to perform some background work, i.e. Logging, wich must not block the main thread. How would I basically design such a scenario? It is obvious that I should do...
2
by: Anbu | last post by:
Hi all, I'm creating processes of a console based application. After proc.Start() the process is not getting terminated and the thread keeps waiting for some reponse from the process. Now I need...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.