HomeBlogBooksProjectsArchiveAboutlogo

Stupid PHP snippet to always download a changing file

06 May, 2012 - 1 min read

It is short, it is easy, it is stupid but... can save you time. If you need to download every few minutes a remote file that changes its contents at regular intervals of time this is for you.

Save this on a stupid.php file (and change the values):

<?php
$url = 'somewhere_in_the_space';
while(true) {
	$locaFile = "some_local_file_name_".time()."_with_extension";
	file_put_contents($locaFile, file_get_contents($url));
	echo "Done... $locaFile \n";
	sleep(60*5);    // Sleep 5 minutes !!!
}
?>

and execute with:

> php -f stupid.php

Remember it will run forever until you kill the process so don't expect to finish.

© I built this site withGatsbyfrom the starterjuliaand made a bunch of modifications. The full content is available in myrepository. Icons made byFreepik from Flaticon