用 ignore_user_abort函数实现php计划任务
说到计划任务大家可能都想到用crontab来实现。可是并不是所有人都是使用linux系统,也不是所有人都有独立服务器。这时候如何用php来
实现计划任务呢。
函数- ignore_user_abort()
,
这个函数可以帮助我们实现像linux中的cron一样实现计划任务,下面一起来看下该如何来实现。
该函数按照字面意思就是“忽略用户中断”,就是使用了该函数的php脚本不管用户有没有退出都会执行下去。
配合set_time_limit 和一个死循环就可以实现计划任务,这样在循环体中,去查询是否有任务需要执行!
例子如下:
ignore_user_abort(); // run script in background
set_time_limit(0); // run script forever
$interval=60*15; // do every 15 minutes...
do{
// add the script that has to be ran every 15 minutes here
// ...
sleep($interval); // wait 15 minutes
}while(true);
但是这个方法也有一个问题,就是当重启了apache之后,脚本就被终止了。
相关文档:
how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled
with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE
9.2, 9.3, 10.0 & 10.1, but most of the steps ought to be valid for all
Linux-like operating ......
本文转自http://xfs39.javaeye.com/blog/411508 感谢作者分享
php单引号和双引号的区别
今天,有一新学PHP的网友问了茶农一个问题:“单引号和双引号的区别和用法?”,现将答案总结了下,写成这篇小短文。
" "双引号里面的字段会经过编译器 ......
<?PHP
/**
* patServer
* PHP socket server base class
* Events that can be handled:
* * onStart
* * onConnect
* * onConnectionRefused
* * onClose
* * onShutdown
* * onReceiveData
*
* @version 1.1
* @author &n ......
$file1 = 'F:/46.gif';
$file2 = 'F:/test.txt';
$file3 = 'F:/47.gif';
$size = filesize($file1);
echo '文件大小为:'.$size;
echo "\n<br>转化为二进制 ...";
$content = file_get_contents($file1);
$content = bstr2bin($content);
$fp = fopen($file2, 'w');
fwrite($fp, $content);
fclose($fp);
......
上次继本人发布了VC编写PHP扩展之Hello World篇后,反映很强烈,大家都希望能脱离PHP菜鸟行列,这次我给大家带来PHP调用C#编写的COM+组件。 COM+组件源代码 CODE:using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Reflection; using System.Data.O ......