我想www.test.com/updateMySqlTables.php
从我的应用程序中打个电话让我们说,但我不想等待进程完成。
像这样的电话
NSString *checkReturn = [NSString stringWithContentsOfURL:checkURL]
但不想等待回报。我希望我的服务器在后台清理表格中的所有旧日期。
我想www.test.com/updateMySqlTables.php
从我的应用程序中打个电话让我们说,但我不想等待进程完成。
像这样的电话
NSString *checkReturn = [NSString stringWithContentsOfURL:checkURL]
但不想等待回报。我希望我的服务器在后台清理表格中的所有旧日期。
是的。加载请求:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"www.test.com/updateMySqlTables.php"]];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
并确保添加将在成功/错误时调用的适当委托方法:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// Success handling here
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// Error handling here
}
我认为您只需要启动一个异步请求并实现其相应的 requestDidDeceiveData: 方法和 requestDidFinish: 方法,并将这两个方法留空,因为您不关心请求可能产生的任何响应。由于它是异步的,它会自动在后台运行。您的应用程序的主线程不会受到影响。
iOS SDK 有自己的方式来发布异步请求。你也可以考虑使用更著名的 ASIHTTPRequest 包来完成你的工作,它更容易设置和监控。
一种方法是在后台线程中加载您的信息,使用 performSelectorInBackground:withObject: 或 [NSThread detachNewThreadSelector:toTarget:withObject:]。两者都需要您创建一个新方法来加载数据。
好的,既然删除了 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();
//Do some work
盗自:http ://andrewensley.com/2009/06/php-redirect-and-continue-without-abort/
我知道在 Linux 中可以在后台运行 php 脚本。
我想在某些配置中使用 exec 可能会有限制。
exec ("/usr/bin/php yourscript.php >/dev/null &");
在后台运行 php 脚本 (&) 并将 sneds 输出到无处 (/dev/null)