|
Posted by Lawrence Krubner on June 5, 2008, 4:27 pm
Please log in for more thread options >> Do any problems come up when using a static variable in a cron job?
>> Assuming the cron job is called every 5 minutes for one year. Assume
>> I've got an array that stores the names of which users are logged in to
>> a particular website at the current moment. Would it cause me trouble if
>> I made this array static? If it would cause trouble, what's the easiest
>> way to persist the data? I could use a database, but that seems heavy
>> handed for a 20 line cron script (mostly because I'd have to create a
>> database table).
>
> Counting the users 'logged in to a ... website' is not nearly as
> simple as it sounds - I find it hard to believe you do it in 20 lines
> of code. The fastest route to the goal would be to write your session
> handler using a DBMS backend.
Sorry, I was simplifying somewhat. I'm actually counting all users who
are logged into an Ajax-driven chat room. I decided to build an array of
the usernames, then serialize() the array, then store it as a file,
then, next time the script was called, open the file and unserialize()
the array. The cron is merely for administrative purposes, to alert the
site owner when someone new has entered the chat room.
The script that gets the usernames and serializes the array and stores
it as a file is 30 lines of code, the script that sends the alert to the
site owner is 43 lines of code.
|