www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] PHP script for a cronjob: download file, unpzck, run another php script

  1. #1
    Join Date
    Mar 2005
    Posts
    140

    resolved [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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    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

    eBookworm.us

  3. #3
    Join Date
    Mar 2005
    Posts
    140
    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',
    );

    $ch curl_init();
    curl_setopt_array($ch$options);
    curl_exec($ch); 
    But get an error:
    Warning: curl_setopt_array(): supplied argument is not a valid File-Handle resource

    I am sure the CURLOPT_URL is correct.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    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

    eBookworm.us

  5. #5
    Join Date
    Mar 2005
    Posts
    140
    Thanks, mate, this was it! Solved!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles