2011-03-04 62 views
1

我正在使用一些連接到我的程序的API,並向它發送一些有價值的數據(以XML)。全部通過HTTP完成。 API要求程序回覆(返回一些XML),以確認成功的事務或警告有關錯誤。問題是程序需要在每次交易後立即下載一些圖像。也就是說,它需要回復API並繼續工作以下載圖像。我的問題是如何將該XML返回給API,以便API可以退出並且我的程序可以繼續工作?(cron是不是一個選項。)讓它退出並繼續工作

回答

0

從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 

?>