How can I test a CRON job with PHP?

老子叫甜甜 提交于 2019-12-24 17:16:06

问题


This is the first time I've ever used a CRON.

I'm using it to parse external data that is automatically FTP'd to a subdirectory on our site.

I have created a controller and model which handles the data. I can access the URL fine in my browser and it works (however I will be restricting this soon).

My problem is, how can I test if it's working?

I've added this to my controller for a quick and dirty log

$file = 'test.txt';

        $contents = '';

        if (file_exists($file)) {

            $contents = file_get_contents($file);

        }

        $contents .= date('m-d-Y') . ' --- ' . PHP_SAPI . "\n\n";

        file_put_contents($file, $contents);

But so far only got requests logged from myself from the browser, despite having my CRON running ever minute.

03-18-2010 --- cgi-fcgi

03-18-2010 --- cgi-fcgi

I've set it up using cPanel with the command

index.php properties/update/

the 2nd portion is what I use to access the page in my browser.

So how can I test this is working properly, and have I stuffed anything up?

Note: I'm using Kohana 3.

Many thanks


回答1:


You're not using the correct command for calling Kohana.

Make sure you're using the full path to index.php so you can eliminate any path errors. Here are the switches available for use in Kohana:

  • --uri: Self explanatory
  • --method: HTTP Request method (POST, GET, etc ...) (Overrides Kohana::$method)
  • --get: Formatted GET data
  • --post: Formatted POST data

You should be using something like this:

php /path/to/kohana/directory/index.php --uri=properties/update/

I can't remember if you need double quotes around the value, don't forget to try that if it doesn't work.




回答2:


you probably aren't running Cron with root permissions on that file.

put mailto="youremail@yourdomain.tld" at the start of the cron file to have it email you errors.

If you don't have root access to the cron file (I.E. SSH) I don't know if you can do this in cPanel.



来源:https://stackoverflow.com/questions/2468037/how-can-i-test-a-cron-job-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!