如何使用PHP测试CRON作业? [英] How can I test a CRON job with PHP?

查看:137
本文介绍了如何使用PHP测试CRON作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用CRON。



我正在使用它来解析外部数据,自动FTP到一个子目录



我创建了一个处理数据的控制器和模型。我可以访问我的浏览器中的网址罚款,它的工作原理(但我会尽快限制)。



我的问题是,如何测试它是否工作? / p>

我已将此添加到我的控制器以获得快速和脏的日志

  $ file ='test.txt'; 

$ contents ='';

if(file_exists($ file)){

$ contents = file_get_contents($ file);

}

$ contents。= date('m-d-Y')。 '---'。 PHP_SAPI。 \\\
\\\
;

file_put_contents($ file,$ contents);

但是到目前为止,只有从浏览器自己记录的请求,尽管我的CRON运行时间很短。

  03-18-2010 --- cgi-fcgi 

03-18-2010 - - cgi-fcgi

我使用cPanel使用命令



index.php properties / update /



第二部分是什么



那么如何测试这个是否正常工作,以及我是否填充了什么呢?



注意:我使用Kohana 3。



非常感谢

解决方案

您没有使用正确的命令呼叫Kohana。



请务必使用index.php的完整路径,消除任何路径错误。以下是可在Kohana使用的开关




  • - uri :自解释

  • 方法:HTTP请求方法(POST,GET等)(覆盖Kohana :: $方法)

  • - get :格式化GET数据

  • - post :格式化POST数据



您应该使用这样的:

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



我不记得如果你需要双引号如果它不工作,不要试试。


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

解决方案

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.

这篇关于如何使用PHP测试CRON作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆