Home >Backend Development >PHP Tutorial >A simple step-by-step approach to PHP running timeout

A simple step-by-step approach to PHP running timeout

WBOY
WBOYOriginal
2016-07-25 09:03:181454browse
  1. $stid = isset($_GET['stid'])?$_GET['stid']:0;

  2. $endid = $stid + 100;
  3. $ maxid = 10000;

  4. function dosomething(){

  5. //A time-consuming operation
  6. ...
  7. }
  8. $sql_string=”select * from `table` where id>'$stid ' and id<='$endid' order by id";
  9. $datas = getdata_bysql($sql_string);
  10. foreach($datas as $data){
  11. //Processing data
  12. …..
  13. echo $id." Processing Done.
    ”;
  14. if($id>=$maxid){exit;}
  15. }
  16. if($stid<=$maxid){
  17. $stid = $stid + 100;
  18. $url= "action.php?stid=$stid";
  19. echo $url;
  20. echo '';
  21. }
  22. ?>
Copy code

The dosomething() is a time-consuming operation. Here we reduce the running time by limiting the id range, and automatically run the next step through javascript jump after running. In this way, you can know the results every time you process a batch of data, and if there is an interruption, you will also know where the problem lies.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn