Home  >  Article  >  Backend Development  >  How to execute tasks regularly in php

How to execute tasks regularly in php

墨辰丷
墨辰丷Original
2018-06-13 10:14:191844browse

This article mainly introduces the implementation method of PHP scheduled execution tasks, involving operation techniques such as curl and sleep. It has certain reference value. Friends in need can refer to it.

The examples in this article describe the PHP scheduled execution How to achieve the task.

The specific implementation method is as follows:

<?php
ignore_user_abort();
set_time_limit(0);
$interval = 60*5;
do{
 $url = "http://www.sina.com.cn/";
 $ch = curl_init();//创建一个新的curl会话
 curl_setopt($ch,CURLOPT,$url);//设置需要抓取的cURL
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 //设置cURL参数,要求结果保存到字符串还是页面(1或真表示保存而不输出)
 curl_setopt($ch,CURLOPT_TIMEOUT,2);//最大延续2秒
 $result = curl_exec($ch);//执行
 curl_close($ch);//关闭
 sleep($interval);//休息5分钟
}while(true);
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

PHP How to write a prompt box similar to alert() in js

php method to create a text message board

How to batch generate logos of various sizes in PHP

The above is the detailed content of How to execute tasks regularly in php. For more information, please follow other related articles on the PHP Chinese website!

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