How use the library to execute php files in /application folder?
Closed this issue · 13 comments
Hello.
I have problems to use the library. If the configuration of "cli_path" in config/crontab.php is done to execute files (with cronjob) outside /application folder. Files are executed correctly but not if the config is done to execute inside /application folder. I need to execute files inside because they use some controller functions.
Can you help me?
- Can you please tell me what path are you setting for
cli_path
config variable? - Can you post what you are have in resulting cronfile?
- I've tried
$config['cli_path'] = base_url().''.APPPATH.'cronjobs/';
and$config['cli_path'] = base_url().''.APPPATH.'controllers/cronjobs/';
* * * * * /usr/bin/wget http://example.com/codeigniter/application/cronjobs/CronJob.php
and* * * * * /usr/bin/wget http://example.com/codeigniter/application/controllers/cronjobs/CronJob.php
I use wget
instead of php
Wow. This library was meant to be used with cli php (so nothing will invoke any server interaction) to reduce load time. But seems like you got it working this way.
- You need to adjust your cli path so you will have something like
http://example.com/cronjobs/cronjob/task
, wherecronjob
- your controller andtask
- your action for cronjob. - Looks OK to me, in case you are have accessible
http://example.com/codeigniter/application/cronjobs/CronJob.php
from your browser (or inside your serversloopback
interface).
I have not accessible http://example.com/codeigniter/application/cronjobs/CronJob.php
from my browser because Codeigniter has that security. Controllers are in /application/controllers folder, and I think that if I put them outside of /application folder isn't good for my application. I've tried with executable files outside to test and they work, but that isn't my purpose
Please read my previous comment:
You need to adjust your cli path so you will have in result something like http://example.com/cronjobs/cronjob/task
, where cronjob
- your controller and task
- your action for cronjob.
But it's better to move your controller shared code to a library and use cli php for cron jobs.
But, http://example.com/cronjobs/cronjob/task
, cronjobs
folder would be outside of /application folder
. Is not?
They would be in the same level.
if you want to use wget you must call a usual codeigniter controller/cation
so yes, any of controller will be inside /application
directory
Can you explain it? I don't understand
If you want to use wget - you should make your cronjob tasks to be executable from browser. Think about wget as "commandline browser without view"
If I use php
, is not the same? can I make cronjob tasks inside /application
folder? Another solution? Security is very important in my web application.
- not sure what you mean.
- yes
- another solution is up to you.
Ok. Thanks.
But, Is it posibble to call functions? For example: $this->crontab->add_job('* * * * *', 'file.php function');
You can read about it in appropriate PHP manual http://www.php.net/manual/en/features.commandline.php http://php.net/manual/en/reserved.variables.argv.php