Codeigniter - Running Cron without Cron Tab - php

Trying to figure out how to run a cron without using Cron Tab. I have my app setup on a shared hosting (client) of which has an Admin UI method for doing Cron Jobs. It's asking for path to a PHP file and won't let me write a controller or method after the file. See following image.
Here are their docs on what's possible:
https://docs.ovh.com/fr/fr/web/hosting/mutualise-taches-automatisees-cron/
On my dev server I am using Cron Tab and line looks like this:
0 8 * * * curl http://<site_here>/crons/<function_name>/
How should I fill out the Command to be executed line? Should I move my function to index or call it from the __construct if that's even a possibility (or wise)?

Related

Cron jobs and php scripts

So, i have a script that calls 2 other scripts that back up devices.
Problem is, If i call the main script manually that opens up the other two in a screen session, everything works fine.
The 2 scripts it calls basically sends data to an sql server via a php script.
IE
I have the line
$link = mysql_connect("server ip", "username", "password", "database");
Running manually (Which runs from my user directory) it works fine.
If i have the cron job run, it will run fine to a point when it gets to the php section of the script it gets the error
PHP Fatal error: Call to undefined function mysql_connect() in /export/home/myname/my_Scripts/php_script_its_running
So, being that it works correctly if i manually run it, and not when i run it via cron, I am assuming it is either running a different php instance due to it being run by cron or something oddball like that? or, idk, not 100% familiar with cron jobs yet.
So while i was debugging it more, it looks to be using a different version of php than what my user account is using, 5.1 comparred to 5.4
Not sure if there is an easy way to change it to use my user accounts php setup? Unfortunately i have no root access to the box.
Answer
So, i ran a working script, and added phpinfo(), grabbed the path information and added that to the cronjob so it would overwrite the defaults.
so the top of the cronjob file looks something like
SHELL=/bin/bash
PATH = /usr/kerberos/bin:/app/php-5.4.3/bin
Answer So, i ran a working script, and added phpinfo(), grabbed the path information and added that to the cronjob so it would overwrite the defaults.
so the top of the cronjob file looks something like
SHELL=/bin/bash PATH = /usr/kerberos/bin:/app/php-5.4.3/bin

cronjob executing a php file

So I have a php file that executes each time it you reload it in the web browser. It uses PHPMailer, to send mail based on criteria in my db. I was attempting to use a cronjob to execute the file which I thought would basically do the same as reloading the page. The php file that I need to run in the cronjob is test.php, and its path is /var/www/html/mailer/test.php.
My cronjob is:
1 * * * * root /var/www/html/mailer/test.php >> /var/www/html/mailer/cron_status.log
and it should be throwing errors into that cron_status.log file, but its empty. I realize that this is firing every minute, but I'm just doing it to test the cronjob, and I really need to set it to 24hrs. With no error output, and no emails landing where they should be, I don't think I've properly setup my cronjob. This is my first time ever trying this. This is on a centos 7 droplet, and I've followed the tutorial from digital ocean with no success.
I need to see the php file to be sure, but you probably need to change it to this:
1 * * * * php /var/www/html/mailer/test.php >> /var/www/html/mailer/cron_status.log

Run php file as cron job in windows 8.1 using php.exe

We are trying to setup php file into cron job in windows 8.1 system, to call GCM push notification and to get notification in our registerrd devices.
It works fine when we run cron using any browser like Chrome , Firefox then I get GCM push notification to my registered device but, If we try same configure using php.exe then we are not getting notification to our devices.
To schedule cron we are using Task Scheduler in that our trigger setting are like :-
And in our Action tab We have set up bellow lines:-
Program / script :- D:\xampp\php\php.exe
Add arguments (optional) :- -f D:\xampp\htdocs\PushNotificationSql\tasknotification.php
Start in (optional):- D:\xampp\htdocs\PushNotificationSql
After that We run manually then We get response as per below image but can not get notification into registered device.
Any help will be appreciate!
After many hurdles we got the solution of our problem
We have face three problems to make working this.
1). We have change our ActionTab to this
Program / script :- D:\xampp\php\php.exe
Add arguments (optional) :- -c D:\xampp\php\php.ini -f D:\xampp\htdocs\PushNotificationSql\tasknotification.php
Start in (optional):- [Remain empty]
This will successfully call php script from cmd using php.exe
2). In our php script there is code which is called php function from javascript and we knows that script code does not run using cmd its only handle by browser so we have change it and then it works fine.
3). And we have another php file include into this cron php file [tasknotification.php] so we have to write pull path of that included file.

Laravel cronjob not running on the server

I wanted to ask how automation of tasks aka cronjobs on a website are run using laravel commands?
I created a command following the tutsplus tutorial and call my functions in the fire method below:
public function fire()
{
$feeds= new FeedsController;
$update='update';
$feeds->getUpdateYoutube($update);
$feeds->getUpdateInstagram($update);
$feeds->getUpdateTwitter($update);
$feeds->getUpdateFacebook($update);
$feeds->getWriteToFile();
$this->info('Success');
}
However, this does not get called at all, despite the fact I included it called it on the server like so: 0 */2 * * * php /home/path/public_html/website artisan feeds-refresh
any clues what I am doing wrong?

Cron job is not giving required result, but accessing same file through browser does

I need to run a php script to generate snapshots using CutyCapt of some websites using crone job, i get websites' addressess from database and then delete this record after generating screenshots.
i used */5 * * * * /usr/bin/php -f /path/generate.php
it didn't worked for crone job but if i access the same file using browser it works fine, and if run this script using command php from command line it also works fine.
then i just created another file and accessed the url using file_get_contents; added this file to crone job it worked fine for some days but now this approach is also not working. i don't know what happened. i didn't change any of these files.
I also tried wget command to access that url but failed to get required out put.
my crontab is now looks like this
*/5 * * * * wget "http://www.mysite.com/generate.php" -O /dev/null
Strange thing is that crone job executes fine it fetches data from database and deletes record as well but does not update images.
Is there any problem with rights or something similar that prevents it to generate images using crone job but not when accessed using browser.
Please help i am stuck.
I don't know what your script is doing internally, but keep in mind that a user's cron jobs do not inherit the users environment. So, you may be running into a PATH issue if your php script is running any shell commands.
If you are running shell commands from the script, try setting the PATH environment variable from within your php script and see if that helps.
is there any user credintials on this page , such as Basic authentication ?
if so , you have to define the user name and password in wget request like
wget --http-user=user --http-password=password "http://url" ?
and try another solution by running yor script from php command line
so your crontab could look like
*/5 * * * * /usr/bin/php -f /path/to/generate.php
try this solution it will work and it is better than hitting the server to execute background operations on your data
and I hope this helps

Categories