问题
I am attempting to scrape an url from reddit and post it on my blog every 30 minutes. This is my current solution:
I created a php file named 'newpost.php' that fetches content from the reddit's api and posts it to my blog. (Every time the page is loaded it fetches/posts the newest reddit post). Here is the code:
$json = file_get_contents("https://www.reddit.com/r/all/new.json?limit=1"); $obj = json_decode($json); $url = $obj->data->children[0]->data->url; // the rest posts this url to my blog
I then created a cron job that runs this code every 30 minutes
wget --no-cache --spider http://mywebsite.com/blogposter/newpost.php
My problem is that when the cron job runs it's 2nd time (after 1 hour) it is posting the same url as the first time. This only happens with the cron job. When I manually refresh my page in a browser every couple of minutes it posts a different url every time.
I think something is getting cached, but I'm not sure what. Any suggestions?
来源:https://stackoverflow.com/questions/31443924/trying-to-fetch-the-latest-reddit-post-with-the-reddit-api