简体   繁体   中英

Execute php script even if user leaves page

I would like to run a php script that collects data from an other site (something like a crawler) for the time the user has specified. Ex. If user choose to crawl for 5 minutes, the php will start and run for 5 minutes, even if the user leaves the page. He then comes back and can see the results.

ignore_user_abort — Set whether a client disconnect should abort script execution

http://php.net/manual/en/function.ignore-user-abort.php

There are more things to consider like script execution timeouts. A more 'enterprisey' way to do this is to offload the work to a job or message queue.

I think you should look at crontab /cronjob (if you use a linux webserver).

You can then make a database of what should be crawled and for whom.

And if you do not have a login system, you should link the crawl result to a session or cookie from the users browser.

When the script and database is made, you can make the php script that collects data to run every minute with this command in SSH/Telnet:

*  *   *   *   *   php /path/to/script.php

If you do not have access to the SSH/Telnet shell, most control panels has a crontab function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM