Using launchd to run a PHP script

The good old cronjobs are deprecated in macOS and launchd is the preferred way nowadays. It's the first time for me and it took me a while to get it working. At first I didn't realize you need to add multiple elements for a program with parameters. Secondly, symlinks didn't work for me. I had to use /Users/username instead of the symlink I had (/www/). I'm not sure why.

Here is the plist file I used:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

It should be named like "com.companyname.somename.plist". You can place it in $HOME/Library/LaunchAgents and then load it via launchctl load com.companyname.somename.plist.

comments powered by Disqus