phpcodeignitercron

how to run from godaddy a console php order with codeigniter


Sorry about my english. I was searching about 2 days without answers. the problem is:

i need to run a cron job. I write in console from ssh in godaddy this:

/web/cgi-bin/php5 /path/to/my/project/html/www/myproject/index.php crons test

and i get:

Status: 301 Moved Permanently
Location: http://www.
Content-type: text/html

i have in .../application/controllers the file crons.php which have this code:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Crons extends MY_Controller {

public function __construct() {
    parent::__construct();
}

public function test() {
    echo "hello word";
}

}

/* End of file crons.php */
/* Location: ./application/controllers/crons.php */

it is going to my index.php but it is not working because in my index.php i have this code for redirect .mysite to www.mysite, and $getsite_all is the error:

$getsite_all = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$getsite = $_SERVER['HTTP_HOST'];

$getsite = str_replace($e_dom, '', $getsite);

$ugetsite = explode('.', $getsite);
if ($ugetsite[0] != 'www') {
    $estimated_url = 'http://www.' . $getsite_all;
    header('HTTP/1.1 301 Moved Permanently');
    header("Location: $estimated_url");
    die();
}

but if i delete this lines the error is from that lines:

// Is the system path correct?
if (!is_dir($system_path)) {
    exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: " . pathinfo(__FILE__, PATHINFO_BASENAME));
}

so i think that the error can come from my .htaccess which is:

<FilesMatch "\.(css|js|gif|jpe?g|png|ico)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
</FilesMatch>
FileETag none
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /


    # Impide el acceso a la carpeta del sistema
    # "system" se debe cambiar si el nombre la carpeta se modifica.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    # Esto impide el acceso a la carpeta de la aplicación
    # 'application' se debe cambiar si el nombre la carpeta se modifica.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)/$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^(.+)/$
    RewriteRule ^(.+)/$  /$1 [R=301,L] 

    # Comprueba si el usuario está intentando acceder a un archivo válido,
    # como un documento de imagen o CSS, si esto no es cierto
    # se redirecciona a index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index.php|css|js|images|robots.txt)
    RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

i think the error can be in:

 RewriteCond %{REQUEST_URI} ^system.*
 RewriteRule ^(.*)$ /index.php?/$1 [L]

but my web is running perfectly and i dont know if delete this lines.

What i must do?

Thanks!


Solution

  • ok it was very simple. in godaddy you can put directly:

    wget http://www.example.com/mycontroller/mymethod 
    

    in my example:

    wget http://www.example.com/crons/test 
    

    and it works perfectly. what i cant understand is why goddady dont put that simple information in his cron job panel.