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