Troubleshooting
Here are some issues you may encounter down the road.
-
Connect to MySQL after you start() the daemon.
Otherwise only the parent process will have a MySQL connection, and
since that dies.. It's lost and you will get a 'MySQL has gone away'
error.
-
Error handling
Good error handling is imperative. Daemons are often mission critical
applications and you don't want an uncatched error to bring it to it's
knees.
-
Reconnect to MySQL
A connection may be interrupted. Think about network downtime or
lock-ups when your database server makes backups. Whatever the
cause: You don't want your daemon to die for this, let it try
again later.
-
Write your own php error handler
It should forward all the PHP errors to the log() method, so they end
up in your logfile. Otherwise it's very hard to spot errors, since the
daemon has no way of writing to your console anymore! See
set_error_handler.
-
Monit
Monit is a standalone program that can kickstart any daemon,
based on your parameters. Should your daemon fail, monit will
mail you and try to restart it.
I know I'm saying MySQL a lot, but you can obviously replace that
with Oracle, MSSQL, PostgreSQL, etc.