简体   繁体   English

计划工作:CodeIgniter2 + Doctrine2如何使它工作?

[英]cron job: CodeIgniter2+Doctrine2 How do I get this to work?

I am attempting to use cron to run a PHP file that executes a series of actions. 我正在尝试使用cron运行一个执行一系列操作的PHP文件。 I've done this before with simple procedural PHP, the trick then was doing the cron like this: 我之前使用简单的过程PHP做到了这一点,然后的窍门是执行cron这样的操作:

/usr/local/php5/bin/php /home/me/fullpath/turnrun.php / usr / local / php5 / bin / php /home/me/fullpath/turnrun.php

and having this at the very top of the PHP file I wanted executed. 并将其放在我要执行的PHP文件的顶部。

#!/usr/local/bin/php -q

I'm using CodeIgniter 2 and Doctrine 2, so I have controllers and classes and all kinds of fancy stuff now, and I can't figure out how to make this work. 我正在使用CodeIgniter 2和Doctrine 2,所以现在有了控制器和类以及各种奇特的东西,而且我不知道该如何进行工作。

When I attempt to run a 'backend_test_turn.php' file I get an error 当我尝试运行“ backend_test_turn.php”文件时,出现错误

Parse error: syntax error, unexpected T_STRING in /home/me/fullpath/application/controllers/backend_test_turn.php on line 59 解析错误:语法错误,第59行的/home/me/fullpath/application/controllers/backend_test_turn.php中出现意外的T_STRING

This file includes 该文件包括

class Backend_test_turn extends CI_Controller {

    // code

    $logmsg = new ORM\Dynasties2\Systemlog;   // <---  this is line 59

    // code

}

Note that when I run this normally (in a browser), the code works fine and does not throw an error. 请注意,当我正常运行此命令(在浏览器中)时,代码可以正常工作,并且不会引发错误。

What am I doing wrong? 我究竟做错了什么?

You can run the controller code directly from command line like this: 您可以像这样直接从命令行运行控制器代码:

php index.php Backend_test_turn/action/data

OR 要么

php index.php Backend_test_turn action data

You can find more help here . 您可以在此处找到更多帮助。

you can try 你可以试试

$logmsg = new ORM\Dynasties2\Systemlog;
$logmsg = new ORM\Dynasties2\Systemlog(); // <- see difference

Did you try to use CURL instead? 您是否尝试使用CURL?

I have an application CI & Doctrine with CRON jobs and I've got many errors like yours while trying to launch controllers via CLI. 我有一个带有CRON作业的应用程序CI&Doctrine,并且在尝试通过CLI启动控制器时遇到了很多类似您的错误。

Personnaly now I use CURL instead of CI CLI and it works like a charm. 现在,我使用的是CURL而不是CI CLI,它的工作原理很吸引人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM