Skip to content

Instantly share code, notes, and snippets.

@FatihGoktas
Last active February 3, 2020 06:59
Show Gist options
  • Save FatihGoktas/fed2ed39ab0a0cff27b9ae16de62761d to your computer and use it in GitHub Desktop.
Save FatihGoktas/fed2ed39ab0a0cff27b9ae16de62761d to your computer and use it in GitHub Desktop.
Add crontab command to server by PHP script
// you will see nothing here
$output = shell_exec('crontab -l');
echo "Before<br>";
var_dump($output);
echo "<hr>";
// Create a temporary file and put into our crontab command line
// I wrote an order that will work every minute
file_put_contents('/tmp/crontab.txt', $output.'1 * * * * curl http://example.com/test_1.php'.PHP_EOL);
// Should run our temporary file
echo exec('crontab /tmp/crontab.txt');
// Let's have a look our crontab job list
$output = shell_exec('crontab -l');
echo "After<br>";
var_dump($output);
echo "<hr>";
exit();
/*
* If you want to check crontab list in terminal
* must to login by www-data, follow these commands;
* su -s /bin/bash www-data
* crontab -l
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment