Codeigniter CLI working in terminal, not in Cpanel cron - codeigniter

I have problems setting up a cron using CodeIgniter. I've followed the documentation and set up a test cron
* * * * * php /home/USERN/public_html/spider/index.php tools message
But this doesn't work. The output is just the index.php default controller, and not tools/message. When I run it in the terminal on the server, I get the results that I expect. Is there something I am doing wrong, or do I need to change something on the server?

For cPanel servers, in order to for CI to use the URI segments right, You'll have to use
/usr/local/bin/php

Related

Magento Cron on shared hosting (hostinger)

How can i set up magento cron properly on shared hosting servers, where execution is prohibited via SSH?
i.e Setting up using crontab doesn't work. The temporary solution i have is the following:
*/10 * * * * php public_html/bin/magento cron:run
*/15 * * * * php public_html/bin/magento cache:clean
*/5 * * * * php public_html/bin/magento indexer:reindex
I have inserted these into the cron job section in cpanel.
This is probably a hideous way of tackling this problem, but atleast indexers are reindexed automatically right now. But when the site goes public, this needs to be set up correctly.
Running Magento 2.1.17
Your cron task for the scheduler is fine, but the other two are a bit weird.
Why do you need to clear your cache & reindex so often ?

Magento Cpanel Cron Job not working

I cant get the Cron Job set up on our server to send out password resets and email confirmations. Have I set it up correctly? Have tried many different ways - the latest being:
curl -L -s http://www.****.com/cron.php
*/5 * * * *
Is this right? Ideally I'd like to set it to instant for now so I can see if is working, then change to every 5 minutes.
Update: I've been told by our server provider it has been set up properly, so is there anything within Magento I should check?
Thanks.

Debugging for LDAP authentication for Moodle

I have configured the LDAP authentication and added /auth/ldap/cli/sync_users.php to the crontab as described in the official manual: http://docs.moodle.org/26/en/LDAP_authentication.
But with no luck the LDAP thingy seemed to be failing to work properly. I believe the cron job has been set up properly, so I suppose I may have made some mistakes, or not providing enough information in the configuration for the LDAP authentication plugin.
As the cron script must be called from the command line, and I only have access to the FTP and MySQL database on the server, I have no idea how to execute the file to check if there are any errors (for debugging purpose).
So, I would like to know the proper way(s) to debug the LDAP authentication.
Please let me know if I am not making it clear enough. I could provide more details if needed.
Thank you.
UPDATES * * * *
I have tried to run the /admin/cron.php on a browser, and I have found the following lines in the output.
Running auth crons if required...
... started 10:24:18. Current memory use 27.9MB.
Does it have anything to do with the LDAP authentication? And what does it imply here?
Have you got something like this in your cron?
*/15 * * * * /usr/bin/php /path/to/moodle/auth/ldap/cli/sync_users.php >/dev/null
You could probably redirect the output to a log file to see whats going on.
*/15 * * * * /usr/bin/php /path/to/moodle/auth/ldap/cli/sync_users.php > /path/to/home/ldaperrors.log 2>&1
Also try it with debugging - add these to the config.php - not on a production site though, otherwise your users might see lots of errors.
#error_reporting(E_ALL | E_STRICT);
#ini_set('display_errors', '1');
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
For those who stumble upon this via a search...
In Moodle 3.0 and above, cron jobs can be viewed and run from Site Administration>Server>Scheduled Tasks.
Very useful to view output of the task (in this case the LDAP authentication).

scheduled http call on AWS elastic beanstalk

I've been searching for a while and think I have part of the information I need but just need some assistance putting it all together.
What I'm trying to achieve is to call a URL (a codeigniter controller) on a regular basis e.g. every 5 minutes which will go through my database mail queue and send the mail using amazon SES.
So far I have successfully created the controller, model, DB and SES is working just fine. The controller sends 10 emails at a time and it all works fine when I manually hit the URL.
I'm not too familiar with cron jobs, but think this is where I need to head.
My application is set up on Elastic beanstalk on AWS.
I think that I need a folder called .ebextensions in my web root, with a file called something.config in it, where I can put some 'container commands'. I also think I will need to include 'leader_only: true' in there somewhere to avoid my replicated instances doing the same jobs.
When I don't understand is what should my container command be, considering controller is 'http://myapplication/process_mail' ? From examples I've seen I couldn't see how it determines the frequency, or even the code that 'calls' the URL.
In my controller, I previously had the following code to ensure it could only be called from the command line. Is this something I can keep and have or will the container command just hit the URL like any other user?
if (!$this->input->is_cli_request()) {
echo "Access Denied";
return;
}
Thanks in advance for any help at all. I think i just need help with what should go in the config file, but then again I may have gone down completely the wrong path altogether!
UPDATE:
So far I've got as far as this:
I believe i need to run the application from the commandline like this http://ellislab.com/codeigniter/user-guide/general/cli.html
so my command would be php index.php process_mail
So what I actually need is help with running this command evey 5 minutes. This is what I have so far:
container_commands:
send_mail:
command: php index.php process_mail
leader_only: true
But what I don't understand is how I get this to run every 5 minutes, rather than just when the instance is set up. Do I need to create a cron job file on instance creation, with the php command in it instead?
Update 2:
To anyone else with the same problem, i got this sorted in the end like this:
an ebextensions file that looks like this: (.ebextensions/mail_queue.config)
container_commands:
01_send_mail:
command: "cat .ebextensions/process_mail.txt > /etc/cron.d/process_mail && chmod 644 /etc/cron.d/process_mail"
leader_only: true
a file called process_mail.txt in the same folder that looks like this:
# The newline at the end of this file is extremely important. Cron won't run without it.
*/5 * * * * root /usr/bin/php /var/app/current/index.php process_mail > /dev/null
So, every 5 minutes it runs via the cmd line the codeigniter main index file, passing in the controller name.
thanks to this: https://stackoverflow.com/a/15233848/2604392
I would set up the cron job to talk to the url, then store result in a MySQL database. Then regular PHP or any other app can connect to MySQL and access the data. That's the suggested way to connect to Twitter since a few months, so you can find info on how to do this floowing search for Twitter connectivity.
Hope this helps
By the way, while writing an email generating PHP script, I noticed that I have to slow down the pace of email sending to avoid being flagged as spammer. I added a delay of 2 seconds between emails and it did the job. My database was only 2500 so no big deal (except taking care of changing the PHP_MAXEXECUTION time variable)...

Request a webpage with Cron

I have an MVC architecture and since I already have an action that would be extra useful if automatically called every hour or so, I wondered if there's a way to set it up as a cron job?
Don't know how periodic web page request is related to mvc, but you can achieve this by adding following line to crontab (1 hour period):
0 0/1 * * * wget <web_page_url>
Which is translated to: use wget command to request <web_page_url> every hour at zero minutes.
You can use
curl http://example.com
Or if the language you're using has a CLI client like PHP you could just run the script like
php /var/www/example.com/index.php
Edit:
For an MCV app it's probably easiest to use curl

Resources