How do I setup a cron job a script that is part of a zend framework project

后端 未结 3 1293
难免孤独
难免孤独 2021-02-20 10:58

I have a zendframework project for which i need to run a script periodically to upload the content of a folder and another do download. The script itself is ready but I am strug

3条回答
  •  情书的邮戳
    2021-02-20 11:24

    First, make sure you have this at the top of your PHP script (followed by the opening PHP tag):

    #!/usr/bin/php
    

    Second, make sure the permissions are right. For example, if you create the cron job under root, then I believe root will try to run the PHP script if I'm not mistaken. Likewise, if you create the cron job under a different user, they better have the correct permissions to the PHP script.

    For example (note, depending on your server environment, the permissions will need to be adjusted accordingly. e.g. this is just a hypothetical example)

    $ chmod 755 script.php
    $ chown userThatRunsScriptWithCron script.php
    

    If you want to see the current cron jobs for the current user you're logged in as, do this:

    $ crontab -l
    

    Or, if your cron job is set up in one of the folders such as cron.hourly, cron.weekly, etc, then you can view which user "owns" those jobs by doing this:

    $ cat /etc/crontab
    

    Then at the bottom of the file you'll see them.

    Now, to setup the cron job run this command to open the editor:

    $ crontab -e
    

    Then enter your values:

    1 2 3 4 5 php /path/to/script.php
    

    Now save and close the file. Obviously, you're going to change 1 2 3 4 5 to something real and meaningful. For more information about that see this page (google "cron").


    Disclaimer: I am not a cron master by any means. Please correct me on any of this if I'm wrong.

提交回复
热议问题