Wednesday, May 14, 2014

CakePHP database connection gone while executing a Cron job [solved]

I was working on a CakePHP website that had a script constantly running in background. This script is launched every 10 minutes using Cron and it has a loop that keeps going infinitely until the next launch. It attempts to read some IDs from a Redis key-value store, and then fetches the associated data from the MySQL database.

The problem I got into was that sometimes the script wasn't able to fetch the records from the database, even though they were there. I was confused, because the script worked fine when run using the command line, but not as a Cron task.