使用PHP每n分钟获取一次数据

How can I fetch number of shares every 5 minutes for specified URL?

Here is my code for getting number of shares from twitter:

function twittershares($url) {

 $s = file_get_contents("http://urls.api.twitter.com/1/urls/count.json".
 "?callback=?&url=".urlencode($url));

 preg_match("#(\"count\"):([0-9]*)#",$s,$ar);

 return isset($ar[2]) ? $ar[2] : 0;
 }

 echo twittershares("http://abc1234.com");

Thanks

You're going to want to set up a cron job to run every x minutes - whatever you want - and the cron job will call your script which will run the code you want at that time interval.

This is a tutorial I used when I started learning: Tutorial on setting up cron job

One last edit, this is what the URL of your cron job might look like:

wget -N http://yoursite.com/yourscript.php

well you have two option using pure php 1.Cron job, like ppl have already written or 2. Something more exotic , writing a small php daemon , in case you need to make requests to many urls at the same time.