我想要做一个类似于file_get_content的变体,但是不需要等待内容。基本上我正在请求一个不同url中的另一个php脚本来下载一个大文件,所以我不想等待文件完成加载。有没有人有什么想法?
谢谢!
谢谢!
$fh = popen("php /path/to/my/script.php");
// Do other stuff
// Wait for script to finish
while (fgets($fh) !== false) {}
// Close the file handle
pclose($fh);
如果您根本不想等待它完成:
exec("php /path/to/my/script.php >> /dev/null &");
或者
exec("wget http//www.example.com/myscript.php");
在将下载该文件的脚本运行之前,请尝试以下操作:
//Erase the output buffer
ob_end_clean();
//Tell the browser that the connection's closed
header("Connection: close");
//Ignore the user's abort.
ignore_user_abort(true);
//Extend time limit to 30 minutes
set_time_limit(1800);
//Extend memory limit to 10MB
ini_set("memory_limit","10M");
//Start output buffering again
ob_start();
//Tell the browser we're serious... there's really
//nothing else to receive from this page.
header("Content-Length: 0");
//Send the output buffer and turn output buffering off.
ob_end_flush();
//Yes... flush again.
flush();
//Close the session.
session_write_close();
// Download script goes here !!!
来源: http://andrewensley.com/2009/06/php-redirect-and-continue-without-abort/
在PHP中,如果您想重定向到另一个页面并且希望脚本继续执行而不是立即停止,可以使用以下代码: