TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Make command line detection overridable in Kohana 3.x.x
  • The current method of command line detection,

    Kohana::$is_cli = (PHP_SAPI === 'cli');



    is not supported by all web hosts as not all web hosts have implemented PHP CLI as their command line mechanism, Hostgator being one example of such a web host. It would be great if this could be made such that one can override it without having to make changes in core code.

  • Yes, and I've found once that php-cli hasn't been installed on some hosting and only php-fpm was available for using in console. So had to fix it by hardcoding.

    +1 for this feature request.

  • You can always do your own detection in bootstrap.php after Kohana::init(). Since it's a static variable, I'm not sure how useful this is.

  • Yes, and I've found once that php-cli hasn't been installed on some hosting and only php-fpm was available for using in console. So had to fix it by hardcoding.

    That's not possible, FPM is the fastcgi process manager and can't run PHP from the command line.

    -1 for this request because it's an edge case.

  • @Colonel-Rosa: I missed fpm with php-fcgi

  • Btw, as long as you're here - what do you think about http://forum.kohanaframework.org/discussion/9010/adding-new-log-entry-types ? :-)

  • I think that this is really a good request as there are some who do not support such a command. Though, you could do it manually by hard coding the acceptance of the command but that could really be a tedious task.

    Own detections can also validate this but might as well.

  • For my freak CentOS VPS I only have fast-cgi both through the web server and from command line / CRON.

    I simply had to clone the index.php (named it index_cli.php) set the Kohana::$cli = 'cli'; to separate it somehow, and I always run the CRON job with index_cli.php

  • I'm having the same issue. I tried feketegy's work-around, but it throws an exception in (Access to undeclared static property: Kohana::$cli) so I made this minor adjustment: Kohana::$is_cli = TRUE; (which worked for me :-) ) This is on a shared hosting account. I only have cPanel access and can only run command line via cron.

  • If your PHP_SAPI says fast-cgi, it's not running in cli mode. Your "cron" probably isn't a real cron.

  • @ddrake Sorry it was my mistake. It's Kohana::$is_cli

    @zombor My VPS is setup with CPanel which f**ks up everything... anyways, this definitely has to be improved in future Kohana versions. I lost almost 3 hours yesterday trying to debug this :)

  • @zombor: PHP Server API = CGI

  • @feketegy, I'm not really sure making Kohana lie to you about running in cli mode, when it's not, is an improvement. The CLI SAPI has a lot of differences from CGI. If your host doesn't give you cli access to php it's probably better to design your application in a way that doesn't need it or find a better host.

  • @Isaiah: I see your point about making Kohana lie about cli mode, but I'm having a hard time visualizing another design approach for my application -- maybe you could suggest one... :-)

    My app needs to serve up charts from snapshot data. The snapshots only need to be generated when the tables in the main database are updated (currently once/day). The snapshots are managed in a second database. It seemed to me like a good design approach to have these snapshots generated by the application via a "cron" task. Due to the nature of the queries involved, it would be difficult/ugly to write a MySQL script to accomplish this task.

    Unfortunately changing hosts is not an option...

  • @ddrake, you can use wget with a cron to run your snapshots code daily. You might want to add a security key or something so other people can't run it though. Of course there are downsides to doing it this way, but it's just an example of how you can do it without having to make Kohana think it's running in cli mode when it's not.

    Are you sure your host doesn't have a CLI binary available and you aren't just using the wrong one?

  • @isaiah: Thanks for the suggestions! You may be right about a CLI binary being available -- I'll see what I can find out...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion