关于register_shutdown_function 如何让register_shutdown_function 设置的函数 在脚本中通过exit();结束的情况下不调用,只在意外中断时调用呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phpclass Test { private $running; public function main() { $this->running = true; ob_start(); error_reporting(E_ALL); register_shutdown_function(array($this, "clean_exit")); echo "Hello"; // triggers E_ERROR $fatal->error(); $this->running = false; } public function clean_exit() { if ($this->running) { header("Location: error.php"); } }}$t = new Test();$t->main();?>这是手册上的例子。if就可以了 Good,这是一个很好的思路,用标志位确认是正常退出,还是发生了异常。 <?phpclass Test { private $running; public function main() { $this->running = true; //函数一开始将running初始化为true ob_start(); error_reporting(E_ALL); register_shutdown_function(array($this, "clean_exit"));//注册退出函数 echo "Hello"; // triggers E_ERROR $fatal->error(); $this->running = false;//函数结束前将running设置为false,表示函数正常退出 } public function clean_exit() { if ($this->running) { // 仅当running标志为true(因为没有执行函数结束前的$this->running=true,也就表示程序没有正常退出)时执行。 header("Location: error.php"); } }}$t = new Test();$t->main();?> 哦 明白了 可是 这个方法是在执行之前就预定了程序的结果,我register_shutdown_function设置的函数是一个完全独立的函数,想在程序执行过程中动态的影响他 谢谢,我已经解决了。不过还有一个问题,我在本地apache下超过20分钟后会触发register_shutdown_function设置的函数,可是在服务器的IIS下却不行,改怎么办呢? 如何用PHP建立二维数组,并取值 这个功能要如何写? php取出记录后,如何统计相同的记录(在线等) 如何把www.phpclasses.org给抓下来? 请问一个得出数组的方法? VPS装好后网站打开PHP变为下载 急,求一个好的网络商城! 给推荐几个PHP编辑器吧 如何在windows中配置php3及相应数据库 php做为接口返回数据问题 谁会asp转php谢谢 这个问题怎么解决呢
<?php
class Test {
private $running;
public function main() {
$this->running = true;
ob_start();
error_reporting(E_ALL);
register_shutdown_function(array($this, "clean_exit"));
echo "Hello";
// triggers E_ERROR
$fatal->error();
$this->running = false;
} public function clean_exit() {
if ($this->running) {
header("Location: error.php");
}
}
}
$t = new Test();
$t->main();
?>
这是手册上的例子。
if就可以了
class Test {
private $running;
public function main() {
$this->running = true; //函数一开始将running初始化为true
ob_start();
error_reporting(E_ALL);
register_shutdown_function(array($this, "clean_exit"));//注册退出函数
echo "Hello";
// triggers E_ERROR
$fatal->error();
$this->running = false;//函数结束前将running设置为false,表示函数正常退出
} public function clean_exit() {
if ($this->running) {
// 仅当running标志为true(因为没有执行函数结束前的$this->running=true,也就表示程序没有正常退出)时执行。
header("Location: error.php");
}
}
}
$t = new Test();
$t->main();
?>
哦 明白了 可是 这个方法是在执行之前就预定了程序的结果,我register_shutdown_function设置的函数是一个完全独立的函数,想在程序执行过程中动态的影响他
不过还有一个问题,我在本地apache下超过20分钟后会触发register_shutdown_function设置的函数,可是在服务器的IIS下却不行,改怎么办呢?