[Cialug] scipts/php app for wakeonlan

Matthew Nuzum newz at bearfruit.org
Tue Dec 4 13:40:39 CST 2007


On Dec 4, 2007 1:29 PM, Nathan C. Smith <nathan.smith at ipmvs.com> wrote:

> I'm not sure if I would keep the
> settings in a database or not.  If php has some .ini file or plist-type
> libraries I might choose those instead to keep the footprint small
> (sacrificing scalability).


sqlite is really nice. It's got all the benefits of a standard config file
(and more) but with an sql interface.


> What is the best way to schedule a reoccurring item in php?  Use cron to
> run
> a script every 15 minutes or so?
>

I use cron. I usually include something like this at the top of my scripts:

if($_ENV["DEBUG"]) $debug = true;

Then, further down in my code I can do
if ($debug) print("Some status information\n");

This allows me to run my scripts manually as
env DEBUG=1 php myscript.php
and get useful output. Then, once I'm sure things are working I can put them
in cron and they run silently.

Something else I keep meaning to do but haven't actually done yet is if a
fatal error occurs to spit out some useful diagnostic info, for example the
name of the program that's running. I hate getting those cron messages and
trying to figure out which thing died.

<?php
$program_info =<<< INFOEND
Program Name: Session cleanup
Program Description: Runs nightly and clears the sessions table
Version: 1.112 modified 11/28/2007 by Matthew Nuzum
INFOEND

if( !$ok) die("Couldn't attach to database\n$program_info");

-- 
Matthew Nuzum
newz2000 on freenode
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20071204/5fe99a69/attachment.html


More information about the Cialug mailing list