当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Can I delay my next line of code before it being execute?

问题描述:

I have a button in my iOS app when I hit this button it will do this:

  1. call to PHP Server to run the script (which is query DB from MySQL and rewrite it in to SQLite file)
  2. download the xxx.sqlite file

So sometime when my server lag or slow the app will download when the 1st step isn't done yet, maybe I need a way to delay the code or anyway I can check the file whether it's complete the conversion from MySQL to SQLite file ?

thx a bunch for every answers : )

网友答案:

Use synchronous ASIHTTPRequest to your servers. Your app will hang and wait until server finishes with the request and returns the file.

Use asynchronous ASIHTTPRequest if you want to download the connent in the background.

网友答案:

one way is to do something like this

php script:

unlink sqlite.file.md5
generate sqlite.file
calculate md5 sum of sqlite.file and output it in sqlite.file.md5

and the client should do:

download sqlite.file.md5
if not found:
    wait some time and try again (in progress)

download sqlite.file
calculate md5 of sqlite.file and compare it with sqlite.file.md5
if there is a mismatch you probably downloaded in the middle of generation

actually you do not know how much time you need to delay your download, your php script does not know also (for example: depending on the os's scheduler it might starve a bit and every generation can complete in different time interval) you can only know when the generation is complete

EDIT: or you can just insert one record in the end of the sqlite file after generation is complete and then check if it exists in the downloaded file

分享给朋友:
您可能感兴趣的文章:
随机阅读: