How to send a SQL query to database in PHP without waiting for result

两盒软妹~` 提交于 2019-12-02 19:13:22

问题


Working with DB2 and PHP, my ADDs and DROPs take a long time to finish (30 seconds per ADD and DROP). I am curious if there is a way to send my ADDs and DROPs to the database without having PHP wait for a response?


回答1:


I'm fairly certain that most php db controls don't have async methods (too bad). Presuming that you just need to do DB statements that don't interact with the end user you could use pcntl_fork. If you need something else, a solution like this may be more useful.




回答2:


A simple solution is cron to schedule your tasks

http://articles.sitepoint.com/article/introducing-cron

Schedule all the sql scripts you want to run at a predetermined time.




回答3:


You could code up a "standalone" php script and fire it off using a "system" call.

You only problem would how to pass the data to the script. I would recommend you create an intermediate "actions" table where you can instert the desired updates and have the batch script read the actions and apply the updates.

If you have DB2 installed you may have MQ installed as well. If you do, you can look at a solution where you push your update requests into an MQ queue and have them actioned by a triggered program.



来源:https://stackoverflow.com/questions/4347367/how-to-send-a-sql-query-to-database-in-php-without-waiting-for-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!