static text generation

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Nevertheless you can write a daemon in PHP. Daemon runs constantly, it just sleeping but, say at certain time, it wakes up and performs required action.
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

Exactly. It's easy enough to fork a process on unix (and even windows, if you know how).

:)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

dave420 wrote:PHP is a language, and the PHP software is an interpreter. The interpreter can't just gain consciousness and start running bits of code all on its own - it has to be called by something else. If you want PHP to run at a certain time, something has to run PHP at a certain time. PHP code can't just run itself. Neither can perl, java, C, C++ or anything else. Your gripe seems to be with a lack of cross-platform admin-less scheduling software, not a shortcoming with PHP.
Argh.

Third time I'll try to explain the concept to you.

Apache runs as a daemon. Mod_PHP is a module, that Apache can call.

Now, someone accesses a script - a PHP script - which Apache sees, and loads Mod_PHP to process it. No "gaining conscience" needed.

The script contains a command. Lets call it schedule_task(). Schedule_task in turn tells APACHE to - at specific times - use mod_php to process particular scripts, processes, commands, what have you.

Apache runs as a daemon, so it can check a command stack at regular intervals (its not event-driven). The command stack can be as simple as "there is something on the stack, refer to mod_php". mod_php in turn can hold a command stack as simple as "check with script.php". script.php could then hold the scheduled commands.

None of that is a tremendous change from their current operating manner - and none of it is possible today in PHP, which is what the poster asked for.

Please stop attacking me for answering (from experience, and from a genuine need) what the poster asked.

He asked what PHP doesnt have, but could use. I answered. There is no cross-platform solution to this problem, and there could be by modifying PHP (and possibly, slighly, Apache).
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

First off, I'm not attacking anyone! Believe me, it's not an attack. Not even close. I applaud anyone who spends their time helping others.

Your solution follows exactly what I've been saying - using APACHE to be the scheduler. PHP can't do it, as PHP isn't running all the time.
There is no way a slight modification to PHP could yield what you want. You need a modification to the Apache server, which shows it's not a problem with PHP, but with Apache.

The fact it's nigh-on impossible to create cross-platform scheduled tasks isn't something wrong with or missing from PHP, but the environment in which it runs. Because you want this scheduler to run PHP scripts doesn't mean it's shortcoming in PHP, but where you choose to run it :)
Post Reply