Creating a PHP Engine of sorts

As a developer for many years, I have struggeled for a Engine that requires no interaction of a client to server. Allowing an auto involk to load certian scripts at certian times. Like a Ticker of sorts.This would reduce a client-side involked load time with includes. In case im still not very clear on what Im looking for. Think of a script on a server that auto updates your MYSQL data and you never have to goto it or load it. For thoses without their own server who use a hosting company. I have wriiten many Scripts that do vast amounts of datacrunching and processing, user inter-action , and you name it. One thing I have never been able to understand is how to make a script load and just run with-out a client action.

If this is small cheese to you then be kind and inform me of such cheese for i have no clue..

207 thoughts on “Creating a PHP Engine of sorts

  1. Creating a PHP Engine of sorts

    It’s not small cheese….it is a very interesting question.

    Sometimes the best way is to write a simple “command-line” version, which uses all of the libraries, etc of your “gui” version. The only diff is that the front-end, all the rest is abstracted into the libraries.

    In the real world, sometimes we have to do things a little…er…different.

    For instance, we have this same problem for some of our PHP processes. I didn’t have time to write another “version” so I setup a line in my crontab (cron is just a simple UNIX schedler) like so:

      00 17 * * 0-6 lynx -dump -nolist http://www/tools/pulldata.php

    Now, if you require parms, just add them to the command line. If things get really complex you could even just put the command in a script file and cron that instead.

    If you have not heard of lynx, it is just a text based browser. However, it can also just render an html page to a text file, pass username/passwd, etc…so it helps for scripting web pages. I’m sure there are for more advanced ways out there…but this works for us. If you are in windows, I think that you can even find a windows version of lynx.

  2. Cron
    I agree with Dan and I’ll elaborate a little bit. Using the cron is the way to go. You can do the same thing with windows scheduler, but I’ve never used it for that kind of thing so I couldn’t really explain how.

    I have 8 or 9 programs that I’ve written that run in the cron. Most of them are things that need to run once a day so I have them run at 4:00am or something like that. For instance, I wanted to send daily e-mails to clients concerning the status of their account, so that they didn’t have to log in to see that information every day. So I wrote a php script that gathers all the information I need using mysql queries and compiles and email and sends it to every account in the database. I also have ones that update the database and turn access to accounts off once a certain date hits, etc. Very nifty.

    I started doing this back before PHP CLI (command line interface) came about, so the scripts I wrote use the CGI version of PHP, which is pretty close to the same thing I assume. You have one of those two (CLI or CGI) supported by your server. They are usually compiled seperately from when PHP is compiled as an apache module, so some servers might not support them.

    # This cron job will run my automatic email script at 6:00 am every weekday morning (not on weekends)
    0 6 * * 1-5 /usr/local/bin/php -q /home/dschast/auto_returnrate_email.php

    Take note of the -q after the call to the php executable. I’m not sure if the CLI version has to do this but the CGI version does. PHP will always output a webpage related header if you don’t specify the -q option. auto_returnrate_email.php is written just like any other PHP script, except there is no output. Make sure you don’t ouput anything because cron will send you an email with the output every time it gets run. Although, that is actually a good thing because you can do error checking and have it output errors when they occur and they will be emailed to you.

    Another neat thing about the cron is you don’t have to have root level access to the server to use it. All you need is a shell account, which most virtual host webhosts supply. So if you are hosted on a UNIX server just log in with telnet and type ‘man crontab’ to find out how to use it. Crontab is the program that is used to alter the cron.

    You might need to do a little bit more research but I hope this has helped!

    • Cron
      "You have one of those two (CLI or CGI) supported by your server."

      That was supposed to say "You MUST have one of those two (CLI or CGI) supported by your server".

      That was kind of an important word to leave out. Sorry about that.

      – Doug

Leave a Reply to Doug Schasteen Cancel reply

Your email address will not be published. Required fields are marked *