<?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 ...*/
?>
|