Linux Cron Job Tutorial: running a .php file
All of my database driven games use PHP as a scripting language which is my favorite scripting language by far (okay I’m biased, I’ve been using it for almost 9 years now).
In order to propagate changes each day I setup a cron job, or a scheduled script that will run a certain times of the day. In a nutshell this updates all of the underlying game structure so pets get older, shows automatically run, so forth and so on.
Accessing the Cron
Although you can edit the cron file directly (var/spool/cron/crontabs) it’s easier to use the crontab command and let it do most of the work for you. Open a shell and type the following command. If you’re not a root user you’ll need to use sudo before these commands (and have super user permissions).
crontab -e
Editing The Cron
The syntax for the cron jobs you’ll be adding to this file is:
minute hour day month dayoftheweek /path/to/script
Minute is 0 – 59
Hour is on a 24 hour clock (0 – 23). With military time you subtract 12 from the number to get pm values. For instance take 15 and subtract 12 and you get 3pm. Everything earlier than 12 is am. The only exception are 0 and 12. 0 is midnight and 12 is noon.
Day is 1 – 31
Month is 1 – 12
Day of the week is 0 – 7 where Sunday is 0 or 7
Now to the good part, some examples. Let’s run a file at exactly midnight every day:
0 0 * * * /path/to/file
The asterisks indicate that this script will run every day. If we want to run the file at 12:15 midnight:
15 0 * * * /path/to/file
Let’s run a script on the 30th of the month at 2:45pm:
45 14 30 * * /path/to/file
Now I only want to run this script on October 31st every month every 25 minutes:
25 * 31 10 * /path/to/file
Last but not least I want to run this file every Tuesday at Midnight in March every 10 minutes:
10 * * 3 2 /path/to/file
My only word of caution is running scripts every x number of minutes every single day in small intervals (ie * * * * * or 5 * * * *). This will eat up your CPU and end up locking out all of your other processes.
Emailing Cron Results
By default the cron is setup to email itself to the server every night. You can change which email each cron goes to by putting the following on the line before the cron:
MAILTO="email@test.com" 0 14 30 * * /path/to/file/
Turning Off Cron Emailing
Sometimes having an email sent to you for some mundane script just wastes space in your inbox. That’s okay, you can turn the email feature off also:
5 20 * * * /path/to/script >/dev/null 2>&1
Setting Up A .php Cron File Through the PHP Interpreter
Replace the path to where you php interpreter is as necessary. Follow that by the -q option and the location of the .php file you’d like to run.
0 0 * * * /usr/local/bin/php -q /path/to/file.php
Running A .php File By Accessing It Online
If you’re accessing databases or includes in your .php file then you probably want to run the file as if you were viewing it on the internet from the domain name. You can use the curl command to do that in place of calling the php interpreter:
0 0 * * * curl /path/to/file.php
References
Add comment November 17, 2009
Video Game References: 3D Models, Degrees, Associations & Other Useful Links
I find that I visit so many different sites I can’t keep them straight and I can’t remember to update my delicious account. So I started adding them as resources on my main website when I found one I liked or wanted to go back to someday in the future. Here’s a list you may want to check them out for yourself. I’ve added my own comments and knowledge thrown into the mix:
Game Engines
G3D Engine – good tool libraries, large free model collections
Torque Engine – popular with independent developers
Unreal Engine – it’s a classic… now available for free.
MMO Specific
Unity 3D – in browser 3D MMO games, quickly gaining popularity as an engine. Has iPhone and Wii capabilities.
Byond – not really an engine so much as a point and click game maker
Irrlicht – i really like this one, runs fast, lightweight, nice toolset. Free. Showcase includes
Ogre 3D – i found this one to be way too complicated and not very well planned out. API was hard to use and understand if you want something you can just jump into and start programming.
Flash Specific
SmartFoxServer – Specifically for Flash MMOs. I’ve chosen this one for an MMO I have in production. Free for up to 20 users, license required for 100, 500, and unlimited users ($300 – $3,000 dollars). Showcase games include Club Penguin, Atlantas and facebook’s app YoVille, and Build-a-Bear Workshop.
Red5 Server – Completely open source and free. If you’re looking to build on your own functionality this one is for you
Electro Server – Haven’t had a chance to play around with this one but it has a free 25 user version. Licenses for up to 500 – 200,000 users ($700 to $4,500+) — no unlimited license that I could find. Showcase games include WebKinz, Nickeldeon and Barbie Let’s Chat.
3D Models
TurboSquid – largest collection of models made in Maya
Poitra – expensive but nice stuff
Archive 3D – all free models
3D Extras – free models
3D Software
Maya – industry leader, costs a fortune though
3Ds Max – also an industry leader but cheaper than Maya. Owned by the same company.
Blender – free, can integrate python and lua scripting. Good support community, so-so documentation.
Drawing & Art Software
Photoshop -leading graphic art software, if you don’t have this you might as well quit now…
Painter – exclusively for people drawing with tablets
Gimp – essentially a free version of photoshop
Associations
ECA – Electronic Consumers Association
ESA - Electronic Software Association
ESRB - Entertainment Software Rating Board
IGDA - International Game Developers Association
Artists
Geninne - artist in Mexico, I want her on one of my projects one day
Creative Thursday – artists post to a new topic every thursday, great way to find a diamond in the rough
Illustration Friday – same as Creative Thursday with a bigger following
Simon Reeves – freelance 3D artist. Has done several commercials so I doubt he’s cheap.
Sarah J How – worked with her on graphics for one of my pet games. Highly recommended. She was a texture/character artists for Deep Red Games, looks like she’s running her own studio now.
DeviantArt.com – tons of various artists. As a last resort you can probably find someone here.
Add comment November 10, 2009
Website Optimization & Usability Tools
Thanks to WebPagesThatSuck.com here’s a list of tools you can use to cleanup and optimize your website:
HTML Validation – http://validator.w3.org/
CSS Validation – http://jigsaw.w3.org/css-validator/
Link Validation – http://validator.w3.org/checklink
Readability – http://juicystudio.com/services/readability.php
Color Contrast – http://juicystudio.com/services/colourcontrast.php and http://www.accesskeys.org/tools/color-contrast.html
SEO Keywords – http://www.instantposition.com/seotest.php
Colorblindness Simulator – http://colorfilter.wickline.org/
Image Validation & Accessibility – http://juicystudio.com/services/image.php
Web Page Loading Time Analyzer – http://www.websiteoptimization.com/services/analyze/
Add comment November 10, 2009