php 执行耗时任务 后台执行


// 你要跳转的url
$url = "http://www.baidu.com/";
 
// 如果使用的是php-fpm
if(function_exists('fastcgi_finish_request')){
    header("Location: $url");
    ob_flush();
    flush();
    fastcgi_finish_request();
// Apache ?
}else{
    header( 'Content-type: text/html; charset=utf-8' );
    if(function_exists('apache_setenv'))apache_setenv('no-gzip', '1');
    ini_set('zlib.output_compression', 0);
    ini_set('implicit_flush', 1);
    echo "<script>location='$url'</script>";
    ob_flush();
    flush();
}
 
    // 这里是模拟你的耗时逻辑
    sleep(33);

linux测试成功,windows不行

可处理的扩展 Gearman yii2-queue exec命令等 待研究

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM