Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of magog  >  Content downloader  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: How to use
Class: Content downloader
Download content from many sites at the same time
Author: By
Last change: Add some details
Date: 2 years ago
Size: 1,335 bytes
 

Contents

Class file image Download
<?php

/*... some code ...*/

include_once 'CContentDownloader.php';

// Create CContentDownloader instance
$contRecivier = new CContentDownloader();

// Get contents of all pages in some array
foreach($pages as $k => $page){
    
$uri $page['host'].$page['uri'];
    
// Add source & remember index in stack
    
$pages[$k]['uri_id'] = $contRecivier->addSource($uri);
}

// Get contents of requested url`s
$contents $contRecivier->getContents();

// Proccess contents
if($contents)
    foreach (
$pages as $k => $page){
        if(
            isset(
$contents[$page['uri_id']]) &&
            
is_array($contents[$page['uri_id']]) &&
            
$contents[$page['uri_id']]['error'] === false
        
){

            
$content $contents[$page['uri_id']];
            
            
// Process curl info array (headers)
            
if($content['headers']['http_code'] != 200){
                throw new 
Exception("Incorrect HTTP code ({$content['headers']['http_code']}).");
            }            
            
            if(
strpos$content['headers']['content_type'], 'text/html' ) === FALSE){
                throw new 
Exception("Unsupported format ({$content['headers']['content_type']}).");
            }
            
            
/* ... do something with content */
            
echo $content['content'];
            
        } else {
            
/* proccess curl error */
            
throw new Exception("Curl error #({$contents[$page['uri_id']]['error']}).");
        }
    }

/*... some code ...*/

?>