[RESOLVED] PHP script for a cronjob: download file, unpzck, run another php script
Hey guys!
I have never done a cronjob before. On my provider I have an easy tool to create a cronjob, so all I really need is a script.
My question is whether I can do everything from within PHP and if yes - where to start.
I need to
1. download a file from a remote location
2. unpack it (it is an xml file archived with gz)
3. the run another php script which deals which parses xml file into db
1. See the FTP or cURL functions.
2. See the Zlib functions.
3. Maybe include()/require() the other file? Otherwise, you could shell_exec() it.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Thanks for advice. Am I right that if I use include until the file downloads using CURL it will not proceed to that point in the script?
I did put together a script to download:
PHP Code:
//DOWNLOAD FILE
set_time_limit(0); // unlimited max execution time
$options = array(
CURLOPT_FILE => '/resources/test.gz',
CURLOPT_TIMEOUT => 28800, // set this to 8 hours so we dont timeout on big files
CURLOPT_URL => 'http://xxx.gz',
);
I think it's the CURLOPT_FILE attribute that is expecting a file handle. You might need to do something like:
PHP Code:
$fh = fopen('/resources/test.gz', 'w'); $options = array( CURLOPT_FILE => $fh, CURLOPT_TIMEOUT => 28800, // set this to 8 hours so we dont timeout on big files CURLOPT_URL => 'http://xxx.gz', );
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks