Esempio n. 1
0
 /**
  * Kicks off a download
  *
  * @param array $workload
  */
 private function addToDownloadSlot($url, $extraOptions = array())
 {
     $originalUrl = $url;
     //	if (!is_array($extraCurlOptions)) {
     //	    critical('Expecting the $extraCurlOptions param to be an array, a ' . gettype($extraCurlOptions) . ' was given');
     //	}
     // check the protocol
     $urlInfo = parse_url($url);
     if (!isset($urlInfo['scheme'])) {
         $url = 'http://' . $url;
         $urlInfo = parse_url($url);
     }
     if (!isset($urlInfo['path'])) {
         $url = $url . '/';
         $urlInfo = parse_url($url);
     }
     $shortUrl = $urlInfo['host'] . $urlInfo['path'];
     //	echo ('Adding url ' . $url . ' to download slot now' . PHP_EOL);
     $curlHandle = curl_init();
     $connectionTimeout = 30;
     // 30 seconds
     $downloadTimeout = 60;
     // 60 seconds
     $defaultCurlOptions = array();
     //	$curlOptions = array_replace($defaultCurlOptions, $extraCurlOptions);
     $mandatoryCurlOptions = array(CURLOPT_CONNECTTIMEOUT => $connectionTimeout, CURLOPT_TIMEOUT => $downloadTimeout, CURLOPT_RETURNTRANSFER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_NOBODY => true, CURLOPT_MAXREDIRS => 3, CURLOPT_MAXCONNECTS => 5);
     //        curl_setopt($curlHandle, CURLOPT_VERBOSE, true);
     $urlInfo['scheme'] = strtolower($urlInfo['scheme']);
     //        switch ($urlInfo['scheme']) {
     //            case 'http' :
     //                debug('Protocol is HTTP');
     //                break;
     //            case 'https' :
     //                debug('Protocol is HTTPS');
     //                break;
     //            case 'ftp' :
     //                debug('Protocol is FTP');
     //                break;
     //            default :
     //                debug('The url did not specify the protocol, assuming HTTP');
     //                break;
     //        }
     $curlOptions = array_replace(array(), $mandatoryCurlOptions);
     foreach ($curlOptions as $opt => $value) {
         $success = curl_setopt($curlHandle, $opt, $value);
         if (!$success) {
             critical('Error while setting the curlopt ' . $opt . ' with value ' . $value);
         }
     }
     curl_setopt($curlHandle, CURLOPT_URL, $url);
     //        echo "output filepath is ". $outputFilepath.PHP_EOL;
     //	$file = @fopen($outputFilepath, "w");
     //	if (!is_resource($file)) {
     //	    fatal('Error opening the $outputFilepath ' . $outputFilepath . ', download not started');
     //	    return;
     //	}
     //	curl_setopt($curlHandle, CURLOPT_FILE, $file);
     //        if (isset($post_fields)) {
     //            curl_setopt($curlHandle, CURLOPT_POST, TRUE);
     //            curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $post_fields);
     //        }
     $result = curl_multi_add_handle($this->curlMultiHandle, $curlHandle);
     $ch_array_key = (int) $curlHandle;
     //	$this->activeHttpDownloads[$ch_array_key] = array(
     //	    'url' => $originalUrl,
     ////	    'options' => $extraCurlOptions,
     ////	    'filepath' => $outputFilepath,
     ////	    'filehandle' => $file,
     //	);
     $this->activeHttpDownloads[$ch_array_key] = $extraOptions;
     //	echo 'A download job (#' . $ch_array_key . ') has been added to a free download slot (' . $this->getFreeSlots() . ' free now)' . PHP_EOL;
 }
Esempio n. 2
0
 function tables()
 {
     $result = mysql_list_tables(cfg('db/database'), $GLOBALS['db_link']) or critical(mysql_error());
     $tableList = array();
     while ($row = mysql_fetch_row($result)) {
         $tableList[$row[0]] = $row[0];
     }
     sort($tableList);
     return $tableList;
 }