Linux下用Crontab来实现PHP的定时运行
按正常的方式写PHP,然后在第一行前加一行"#!/usr/local/bin/php -q"
#!/usr/local/bin/php -q
<?
$file = '/htdocs/www/b100/egspace/Bin/test/'.date('H').'-'.date('i').'-'.date('s').'.txt';
file_put_contents($file,date('Y-m-d'));
?>
<?
$file = '/htdocs/www/b100/egspace/Bin/test/'.date('H').'-'.date('i').'-'.date('s').'.txt';
file_put_contents($file,date('Y-m-d'));
?>
把PHP文件属性改为shell文件。
chmod +x test.php
再编辑crontab
crontab -e
加上一行
*/1 * * * * /htdocs/www/b100/egspace/Bin/test.php