让它退出并继续工作
问题描述:
我正在使用一些连接到我的程序的API,并向它发送一些有价值的数据(以XML)。全部通过HTTP完成。 API要求程序回复(返回一些XML),以确认成功的事务或警告有关错误。问题是程序需要在每次交易后立即下载一些图像。也就是说,它需要回复API并继续工作以下载图像。我的问题是如何将该XML返回给API,以便API可以退出并且我的程序可以继续工作?(cron是不是一个选项。)让它退出并继续工作
答
从PHP社区:http://www.php.net/manual/en/features.connection-handling.php#93441
<?php
// important to state not to keep-alive the connection
header("Connection: close\r\n");
header("Content-Encoding: none\r\n");
ignore_user_abort(true);
ob_start();
// echo your output here
$size = ob_get_length(); // determine the size
// YOU NEED TO SEND THE SIZE IN ORDER for the browser/client to know when to stop
header("Content-Length: $size");
// flush buffered output
ob_end_flush();
flush();
ob_end_clean();
// do your image downloads here
?>