phpcronphalconphing

Call phing task from cron


I am stuck from quite a few days,

I need few good ways to call phing task from cron job.

The actual issue is after calling phing task from cron, the php engine cannot locate the build.xml file, which is located to the main directory of my project

build.xml path : abc/build.xml

phing path : abc/vendor/bin/phing

my cron : 1 * * * * xyz/local/www/abc/vendor/bin/phing test


Solution

  • Two possible solutions.

    First one, you can use cd in your cron:

    my cron : 1 * * * * cd /xyz/local/www/abc/ && vendor/bin/phing test
    

    Second solution, use the -f option:

    my cron : 1 * * * * /xyz/local/www/abc/vendor/bin/phing -f /path/build.xml test
    

    If you have problems with relative paths inside your buildfile you should also set the basedir attribute in the <project> tag:

    <project default="help" name="my-project" basedir="/xyz/local/www/abc">
    

    Sources:

    https://superuser.com/questions/155576/linux-how-to-run-a-command-in-a-given-directory

    https://www.phing.info/phing/guide/en/output/chunkhtml/ch02s03.html

    https://www.phing.info/phing/guide/en/output/chunkhtml/ch03s05.html