Re: script "chaining"



Jerry Stuckle wrote:
bill wrote:
Jerry Stuckle wrote:
bill wrote:
Jerry Stuckle wrote:
bill wrote:
Jerry Stuckle wrote:
bill wrote:
Hugh Oxford wrote:
bill wrote:
The project I am converting from DataFlex to LAMP has a asynchronous daemon.

If a task (such as a report) would take too long to run while attached to the browser, the current system writes the data to a database file. The daemon checks that file every 10 seconds and executes the task, writing the data back to database (as a message or report).

Dataflex has the facility to chain to (execute) another Dataflex program so the daemon is small and fast. The daemon runs as a console program (CLI).

Does php have a similar function ?
Other suggestions ?

bill


If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. There are a few differences in how you write it, but it's straightforward enough.

You could kick it off from a web browser using exec(), then use any number of methods to check on progress, just by querying the db.

I had a similar problem to yours, but I just used ajax. Because each ajax is its own http request, there isn't (such) a risk of timeout.

Ultimately however, I would recommend the first approach, but beware of the security caveats.

Indeed, I plan on having it run from cron, every 10 seconds.
The problem is figuring out a good (not even the best) way to invoke a whole bunch of different scripts after I interrogate the database to find out what is queued next.

Probably the worst way of doing things. But if you have a dedicated server, you should be able to do it.

I would gladly entertain ideas for improvement. Can't promise I can sell them, but am willing to try.

Situation:
Interactive web based (intranet only) system that generates "tasks" to be run off-line on a priority basis. Currently each task has its own script to run it.

I'm going to be spending the next year revising and upgrading the system so a few thoughts now will certainly help then.

bill


As Hugh said - you can have tasks kicked off from web pages.


reasonable approach except for the scheduled tasks that are not triggered by user intervention (daily, weekly, monthly, yearly).
I really don't look forward to trying to write the crontab file from a php script. Anyone ever done that ?

bill

Nope, and I wouldn't. You'll generally need root privileges, and you want to NEVER give that to any task running on a web server (even an internal one). And setting task priority will also be a problem.

my thoughts exactly

You want to set up the taks to run offline - fine. I don't understand why you don't just start the tasks? You'll still have the priority problem, but don't need to mess with the crontab.

The scheduled tasks generally run when no one is logged on to start them.

Probably the easiest way would be just to create a script file on the fly to run the programs in the order you want, then start that script. Alternatively, you could put the information into a database and start a generic script to read from the database (after ensuring another copy of the script isn't running already) and start the programs in the order desired.

which brings be back to the original question. Let us assume that I have a generic script run from cron every 10 seconds. It opens the database, picks the next task from the queue and executes it. As of now the only option I see is to have it exec() a new php task. It would then check for another task due and exec() it until there are no more tasks.

It is highly unlikely that it would run for over 10 seconds, but what would be the problem if it were and I had two copies of the generic task running (and, for arguments sake) 10 php scripts being exec()ed ?

bill


It depends on if the tasks overlap. If there is no overlap, there shouldn't be a problem. The only problem I can see is if the two tasks fetch the same row at the same time (before it can be deleted) and try to execute the same thing.

But why start every 10 seconds? How many of these are you going to run a day? If no one is going to sign on, is there a problem with starting every 15 minutes, for instance? A lot less load on a server.

Good point.

The task load is a mix of overnight tasks and "I'm waiting" tasks. I will probably try to have the "I'm waiting" tasks exec()'d from the UI and the other tasks executed every 15 min.

With thanks to all who contributed to this discussion - and for keeping it civil.
bill
.



Relevant Pages

  • Executing Informix dbaccess in a Windows background environment
    ... Our main objective is to execute an Informix stored procedure that will ... to create an sql script file each day, and to execute it using dbaccess. ... connecting to the database server. ...
    (comp.databases.informix)
  • Re: script "chaining"
    ... bill wrote: ... If a task would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)
  • Re: script "chaining"
    ... bill wrote: ... If a task would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)
  • Re: script "chaining"
    ... If a task would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)
  • Re: script "chaining"
    ... If a task would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)