• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CLI issues

Hello all,

Im having an issue with running a part of my app via cli. I think the issue is with how i am using htaccess to redirect part of my site to https. There soesnt seem to be very detailed docs on how to use the CLI approach so is there something special that needs to be done?

Im using core 2.0.2 and need to call 4 methods in a controller daily via cron.
my config file is setup like so as found on these forums in another post
$config['base_url'] = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

This is read from htaccess which is:
IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond $1 !^(index\.php|assets|images|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1

    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} (login|register|my_account|subscribe|assets)
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]

    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !(login|register|my_account|subscribe|assets)
    RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php

Now this all works awesome for the website but seems to break the cron call. The error I get is:

Quote:[email protected]:/****/****/public_html# php index.php cronrun getDaily
PHP Notice: Undefined index: HTTP_HOST in /****/****/****/application/config/config.php on line 17
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined index: HTTP_HOST</p>
<p>Filename: config/config.php</p>
<p>Line Number: 17</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message: Cannot modify header information - headers already sent by (output started at /****/****/****/system/core/Exceptions.php:170)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 671</p>

There are no closing php tags and no session interaction so im not sure just what the problem is.

Thanks for any insight.

You CAN NOT get some environment variable in CLI mode(this including HTTP_HOST), you should give some exception somehow, in your config file for STDIN request!

Ok thanks for the info. Do you have an example of what that would look like?

In config, you could have something like :
if (defined('STDIN'))
   // You should hardcode the base url for cli, otherwise it will fails.
   $config['base_url'] = "http://yoursite.com/";
   $config['base_url'] = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
Above code should fix the error you received, but maybe you will need to tweak your htaccess too if something still goes wrong.

Wow I was totally overthinking this. That worked perfect, thank you!

That worked perfect, thank you!

That's what I was looking for. Thanks

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.