Not working shared hosting cPanel cronjob under Codeigniter

前提是你 提交于 2020-01-25 10:13:40

问题


Despite there are many posts with a similar topic, I couldn't find anyone matching my case that I briefly describe here. This is the testing script

    <?php

    if (!defined('BASEPATH')) exit('No direct script access allowed');
    require 'DashboardBase.php';

    class Hello extends CI_Controller {

            public function message($to = 'World')
            {
                    echo "Hello {$to}!".PHP_EOL;
                    print "Hello {$to}!".PHP_EOL;
                    log_message('error',"Hello {$to}!".PHP_EOL);
            }
    }

    ?>

The web server is under a shared hosting; it is used cPanel; Codeigniter is used.

The external URL that works properly is this: https://pharmacomparison.com/adminPanel/hello/message/federico

I have activated the cronjob output notification on my personal email and it can be noted that I also save the output in an error log.

Here my cronjob definition attempts

  1. (as suggested by CodeIgniter manual): /usr/local/bin/php public_html/adminPanel hello message "federico" --> no email notification; no output in the 'error' log

  2. small modification, added a "/": /usr/local/bin/php public_html/adminPanel/ hello message "federico" --> no email notification; no output in the 'error' log

  3. (supposed wrong in advance, but let's try) /usr/local/bin/php public_html/adminPanel/hello message "federico" --> email notification reporting "Could not open input file: public_html/adminPanel/hello"; nothing in 'error' log

  4. (supposed wrong in advance, but let's try) /usr/local/bin/php public_html/adminPanel/hello.php message "federico" --> no email notification, in 'error' log "ERROR - 2020-01-10 16:09:25 --> 404 Page Not Found: Hellophp/message"

  5. full real disk path: notification email reporting "No direct script access allowed"

Basically, the first two attempts supposed correct generate nothing even no errors. Any ideas?


回答1:


You are not running it correctly, here is how to run a function in codeigniter through CLI.

Please try this

php /usr/local/bin/php public_html/adminPanel/index.php Hello message "federico"

All function calls must go through index.php

php /path_to_project_root/index.php ControllerName function "argument"



来源:https://stackoverflow.com/questions/59684747/not-working-shared-hosting-cpanel-cronjob-under-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!