Reputation: 759
I have a cron job
on my hosting server that is supposed to execute a php
script every 30 minutes. This php
script is used to scrap a csv
file and uptate that data into a database (i'm using MySQL for that). When executed manually that script works - it takes it about 45 seconds
to finish the process.
Now when that cron job
runs i'm getting this message:
Could not open input file.
At first i thought that this might be because it takes over 30 seconds to execute that script so i decided to set the max execution time at the begging of the php script:
ini_set('max_execution_time', 300);
But again the same message came up.
This is my cron job
:
/usr/local/bin/php /home/emmaein/domain.com/folder/script.php?token=d8cn3j
P.S: that token
get variable is sort of a password so it can't be executed by everybody so basically my php
script looks like this:
if($_GET['token'] === 'd8cn3j'){
//open csv
//get data
//update db
} else{
exit('I see you >:)');
}
Upvotes: 1
Views: 2495
Reputation: 120644
When PHP is not running inside a web server, you can't access $_GET
variables (there's no such thing). Instead you should use command line arguments:
<?php
if ($argc > 1 && $argv[1] === 'd8cn3j') {
// Do stuff
}
And then your crontab becomes:
/usr/local/bin/php /home/emmaein/domain.com/folder/script.php d8cn3j
The concept of $argc
(the number of arguments) and $argv
(an array of the arguments) is fairly standard among CLI programs, and is documented on PHP's website.
Upvotes: 5