Welcome Guest, Not a member yet? Register   Sign In
Problem with cronjob
#1

I would like to run a cronjob on my website.
My application is in a folder called app1
So to refer to my index.php, the path is ./app1/index.php
My controller for cronjobs is Cronjobs.php, which is in the application/controllers folder of CI.
In my controller, there is a method called cleanup.

The command for the cronjob is this:
Code:
/bin/php ./app1/index.php cronjobs cleanup

According to CI's documentation about CLI, this is the correct format.
However, it is only executing the index.php. The e-mail that my hosting provider sends to my admin address, contains all html code of the home page, including a lot of php errors.
 
What am I doing wrong?
Reply
#2

(07-15-2015, 10:19 PM)Wouter60 Wrote: I would like to run a cronjob on my website.
My application is in a folder called app1
So to refer to my index.php, the path is ./app1/index.php
My controller for cronjobs is Cronjobs.php, which is in the application/controllers folder of CI.
In my controller, there is a method called cleanup.

The command for the cronjob is this:

Code:
/bin/php ./app1/index.php cronjobs cleanup

According to CI's documentation about CLI, this is the correct format.
However, it is only executing the index.php. The e-mail that my hosting provider sends to my admin address, contains all html code of the home page, including a lot of php errors.
 
What am I doing wrong?

With cron on many hosts you should consider using an absolute path to index.php. On many hosts that ends up being something like:


Code:
/home/<youraccount>/public_html/index.php

Everything else you are doing seems fine. What kind of errors do you see in that email?
Reply
#3

(This post was last modified: 07-16-2015, 12:19 PM by Wouter60.)

The problem is not that my index.php couldn't be found. That seems to work fine.
The e-mail I got, contains a complete html dump of my website's home page, like this:
Code:
X-Powered-By: PHP/5.3.29
Set-Cookie: ci_session=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang="nl">
<head>
...
</head>
<body>
...
</body>
</html>
So, the method cleanup inside my cronjobs controller is not executed.
My Cronjobs.php:
PHP Code:
<?php
class Cronjobs extends CI_Controller {

  function __construct()
  {
    parent::__construct();
    if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
  }

  public function cleanup()
  {
    ...
  }


I also tried the -f parameter in front of the path to index.php, but same result...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB