php执行mysql不等待返回,PHP如何在不等待包含结果的情况下继续执行代码

I'm hoping there is a simple solution here:

My code is basically

....some code.... //populates a MySQL table

include 'run_this_page.php'; //uses data from table above and takes ten minutes to run

....lots more code.... ///also uses data from same table

As the include takes ten minutes to excute, I'd like for it to be initiated and then move on immediately to the next step. Nothing in the include is required for these next steps. I can think of several non-elegant (create a txt file which will trigger a scheduled task in Windows rather than using include etc) ways to achieve this, is there a more elegant method?

*Update*

I'm being attacked (politely) by many over the structure of my script. Let me explain a bit more what the purpose is:

1 - Raw data is gathered from a 3rd party API, filtered via the script and stored in the database. Because of limitations in this API, I have to restrict the requests to small chunks and this can easily take over 20 minutes. From this data I am looking for two distinct result sets. Each one of these sets are stored in its own table. This will soon grow to a dozen result sets in a dozen tables. (I could use only one table, but it makes no difference for our discussion).

2 - Now that I have the result sets, I have two distinct scripts that go out and gather data about each. Because the target 3rd party sites are completely different I wrote the scripts in their own files and simply want them to both run now. Each can take upwards of ten minutes.

I hope this explanation helps

解决方案

A simple method to load PHP asynchronously is to just use jQuery and AJAX.

// php code you want to run 1st ?>

$( "#content" ).load( "example.php" ); // php to run 3rd

// php code you want to run 2nd ?>

OR ...

A more robust solution, if you want to load example.php on demand, would be to run a cron job programmatically when the user clicks a 'process data' button on that page.

Then you could use AJAX to ping the server every 60 seconds until the data is updated and pull it in using the same code from above.

OR ...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值