how to call a function in PHP after 10 seconds of the page load (Not using HTML)

后端 未结 12 983
终归单人心
终归单人心 2020-12-11 02:44

Is there any way to call a function 10 seconds after the page load in PHP. (Not using HTML.)

12条回答
  •  孤街浪徒
    2020-12-11 03:24

    Not really, no. 10 seconds after your page loaded is (at least) 10 seconds after your PHP script finished, i.e. it is no longer running (apart from tricks that try keeping the connection open, which I don't think will work for a time as long as 10 seconds)!

    Therefore, you either need to schedule a cron job on the server side to fire in 10 seconds, or you need a callback from the website, using AJAX.

提交回复
热议问题