_print_immediately("skipping");
    } else {
        _print_immediately("building...");
        $ch = curl_init($package_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if (!empty($proxy_server) && !empty($proxy_port)) {
            curl_setopt($ch, CURLOPT_PROXY, $proxy_server . ':' . $proxy_port);
        }
        $packager_html = curl_exec($ch);
        if (!curl_errno($ch)) {
            $info = curl_getinfo($ch);
            print '<span class="ok">request OK (took ' . round($info['total_time'], 2) . ' seconds)</span>';
        } else {
            print '<span class="fail">request FAILED (error:' . curl_error($ch) . ')</span>';
        }
        curl_close($ch);
        print " - ";
        $build_ok = endsWith($packager_html, "BUILD_OK");
        if ($build_ok) {
            print '<span class="ok">build SUCCEEDED</span>';
        } else {
            print '<span class="fail">build FAILED</span>';
        }
    }
    _print_immediately("</li>\n");
}
?>
    </ul>
  </body>
</html>
Ejemplo n.º 2
0
 private function _processData($multiInfo)
 {
     $handleString = (string) $multiInfo['handle'];
     $this->info[$handleString]['multi'] = $multiInfo;
     $this->info[$handleString]['curl'] = curl_getinfo($multiInfo['handle']);
     $http_url = $this->info[$handleString]['url'];
     $http_code = $this->info[$handleString]['curl']['http_code'];
     $content_type = $this->info[$handleString]['curl']['content_type'];
     $content_length = $this->info[$handleString]['curl']['download_content_length'];
     $total_time = $this->info[$handleString]['curl']['total_time'];
     $starttransfer_time = $this->info[$handleString]['curl']['starttransfer_time'];
     $connect_time = $this->info[$handleString]['curl']['connect_time'];
     // $request_header = $this->info[$multiInfo['handle']]['curl']['request_header'];
     // print_r($this->info[$multiInfo['handle']]['curl']);
     // Close the file we're downloading into
     fclose($this->filehandles[$http_url]);
     $file_exists = file_exists($this->entries[$http_url]);
     $file_size = $file_exists ? filesize($this->entries[$http_url]) : 0;
     $color = 'pass';
     if ($http_code != 200) {
         $color = 'fail';
         $this->failures[$http_url] = "HTTP Error after " . $total_time . " seconds: " . $http_code;
         if ($http_code == 0) {
             $this->failures[$http_url] .= " (possibly too many concurrent connections).";
         }
         unlink($this->entries[$http_url]);
     } else {
         if (!$file_exists) {
             $color = 'fail';
             $this->failures[$http_url] = "Unable to save file after download. Maybe file name is too long?";
         } elseif ($file_size == 0) {
             // Delete it so that we have to download it again if the user refreshes
             unlink($this->entries[$http_url]);
             $color = 'fail';
             $this->failures[$http_url] = "The file is {$file_size} bytes in length.";
         }
         if ($content_length > $this->warningFileSize * 2) {
             $color = 'bigwarning';
         } elseif ($content_length > $this->warningFileSize) {
             $color = 'warning';
         }
         if ($total_time > 10) {
             $color = 'veryslowwarning';
         } elseif ($total_time > 5) {
             $color = 'slowwarning';
         }
     }
     $char = pugpig_get_download_char($content_type, 'MIME');
     _print_immediately('<a class="' . $color . '" href="' . $http_url . '" target="_blank" title="' . $http_url . ' [Response: ' . $http_code . ', Size: ' . $content_length . ' (' . bytesToSize($file_size) . '), Type: ' . $content_type . ', Time: ' . $total_time . ', TTFB: ' . $starttransfer_time . ', Connect Time: ' . $connect_time . '] ">' . $char . '</a>');
     $this->processedCount++;
     if ($this->processedCount % 100 == 0 || $this->processedCount == count($this->entries)) {
         _print_immediately("<br />");
     }
 }
Ejemplo n.º 3
0
function curl_download($Url, $returnMode = 'stdout', $attempts = 0)
{
    $attempts++;
    // is cURL installed yet?
    if (!function_exists('curl_init')) {
        die('Sorry cURL is not installed!');
    }
    if ($returnMode == NULL) {
        $returnMode = 'string';
    }
    $fileHandle = NULL;
    if ($returnMode != 'stdout' && $returnMode != 'string') {
        $dir = dirname($returnMode);
        if (!file_exists($dir)) {
            mkdir($dir, 0777, TRUE);
        }
        if (file_exists($returnMode) && $attempts == 1) {
            return '.<!--Exists - ' . $Url . ' => ' . $returnMode . '-->';
        } else {
            $fileHandle = fopen($returnMode, 'w');
        }
    }
    $ch = curl_init();
    // Now set some options (most are optional)
    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);
    // Set a referer
    // curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 PugpigNetwork");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, PUGPIG_CURL_TIMEOUT);
    if ($returnMode != 'stdout' && $returnMode != 'string') {
        curl_setopt($ch, CURLOPT_FILE, $fileHandle);
        curl_exec($ch);
        $error = curl_error($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        fclose($fileHandle);
        if ($error != '') {
            if ($attempts <= 5) {
                _fill_buffer();
                _print_immediately('<!-- ' . $error . ' retrying...->');
                return curl_download($Url, $returnMode, $attempts);
            } else {
                unlink($returnMode);
                return 'CURL ERROR: ' . $error . ' (' . $Url . ') [attempts: ' . $attempts . ']';
            }
        } elseif ($http_code >= 400) {
            unlink($returnMode);
            return 'CURL HTTP ERROR ' . $http_code . ' (' . $Url . ')';
        } else {
            return ($attempts == 1 ? '*' : $attempts) . '<!--OK - ' . $Url . ' => ' . $returnMode . '-->';
        }
    }
    curl_setopt($ch, CURLOPT_HEADER, true);
    $output = curl_exec($ch);
    $error = curl_error($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($error != '') {
        if ($attempts < 5) {
            return curl_download($Url, $returnMode, $attempts);
        } else {
            return 'CURL ERROR: ' . $error . ' (' . $Url . ')';
        }
    } elseif ($http_code >= 400) {
        return 'CURL HTTP ERROR ' . $http_code . ' (' . $Url . ') [attempts: ' . $attempts . ']';
    }
    $headerend = strpos($output, "\r\n\r\n");
    if ($headerend === false) {
    } else {
        $headers = explode("\r\n", substr($output, 0, $headerend));
        $output = substr($output, $headerend + 4);
    }
    if ($returnMode == 'stdout') {
        //header_remove();
        ob_end_clean();
        ob_start();
        if (isset($headers)) {
            foreach ($headers as $h) {
                if (strcasecmp(str_replace(' ', '', $h), 'transfer-encoding:chunked') == 0) {
                    continue;
                }
                header($h);
            }
        }
        echo $output;
        exit;
    } elseif ($returnMode == 'string') {
        return $output;
    } else {
        return 'Unknown return method in curl_download: ' . $returnMode;
    }
}
Ejemplo n.º 4
0
function _pugpig_package_show_images_in_package($entries)
{
    _print_immediately('<div class="portfolio"><ul id="grid">');
    foreach (array_keys($entries) as $entry) {
        $extension = "";
        $path_parts = pathinfo($entry);
        if (isset($path_parts['extension'])) {
            $extension = $path_parts['extension'];
        }
        $char = pugpig_get_download_char($extension, 'EXT');
        if ($char == 'i') {
            _print_immediately("<li><a href='{$entry}'><img src='{$entry}'></a></li>\n");
        }
    }
    _print_immediately('</ul></div><p style="clear: both;">End of images</p>');
}
 private function _processData($multiInfo)
 {
     $handleString = (string) $multiInfo['handle'];
     $this->info[$handleString]['multi'] = $multiInfo;
     $this->info[$handleString]['curl'] = curl_getinfo($multiInfo['handle']);
     $http_url = $this->info[$handleString]['url'];
     $http_code = $this->info[$handleString]['curl']['http_code'];
     $content_type = $this->info[$handleString]['curl']['content_type'];
     $content_length = $this->info[$handleString]['curl']['download_content_length'];
     $total_time = $this->info[$handleString]['curl']['total_time'];
     $starttransfer_time = $this->info[$handleString]['curl']['starttransfer_time'];
     $connect_time = $this->info[$handleString]['curl']['connect_time'];
     $cinfo = $this->info[$handleString]['curl'];
     // $request_header = $this->info[$multiInfo['handle']]['curl']['request_header'];
     // print_r($this->info[$multiInfo['handle']]['curl']);
     // Close the file we're downloading into
     fclose($this->filehandles[$http_url]);
     fclose($this->headerhandles[$http_url]);
     $name = $this->entries[$http_url];
     $file_exists = file_exists($name);
     $file_size = $file_exists ? filesize($name) : 0;
     if ($http_code != 200) {
         $this->failures[$http_url] = "HTTP Error after " . $total_time . " seconds: " . $http_code;
         if ($http_code == 0) {
             $this->failures[$http_url] .= " (possibly too many concurrent connections).";
         }
         unlink($name);
     } else {
         if (!$file_exists) {
             $this->failures[$http_url] = "Unable to save file after download. Maybe file name is too long?";
         } elseif ($file_size == 0) {
             // Delete it so that we have to download it again if the user refreshes
             unlink($name);
             $this->failures[$http_url] = "The file is {$file_size} bytes in length.";
         }
     }
     $char = pugpig_get_download_char($name, $content_type);
     $headerfile = $name . ".pugpigheaders";
     $curlopt_file_name = $name . ".pugpigcurlopt";
     file_put_contents($curlopt_file_name, serialize($cinfo));
     $headers = file_get_contents($headerfile);
     $headers_array = _getHeadersFromString($headers);
     _print_immediately('<a class="pass" href="' . $http_url . '" target="_blank" title="' . $http_url . "\n" . '[Response: ' . $http_code . ', Size: ' . $content_length . ' (' . pugpig_bytestosize($file_size) . '), Type: ' . $content_type . ', Time: ' . $total_time . ', TTFB: ' . $starttransfer_time . ', Connect Time: ' . $connect_time . ']' . "\n" . htmlspecialchars($headers) . ' ">' . $char . '</a>');
     $this->successes[$http_url]['file'] = $name;
     $this->successes[$http_url]['headers'] = $headers;
     $this->successes[$http_url]['curl_info'] = $cinfo;
     $this->successes[$http_url]['fetched'] = TRUE;
     $this->processedCount++;
     if ($this->processedCount % 100 == 0 || $this->processedCount == count($this->entries)) {
         _print_immediately("<br />");
     }
 }
function _pugpig_package_create_chunked_zips($partname, $filename, $tmp_path, $real_path, $zip_paths, $zip_base_url, $suggested_max_bytes, $verbose = true)
{
    _print_immediately("<h3>Creating ZIPs for {$partname} (with sizes &lt; {$suggested_max_bytes})</h3>");
    $zips = array();
    // Split the paths into groups approx <= $suggested_max_bytes each; works with uncompressed files
    // can go over if individual file too large as ZIP can't handle the file being split?
    $group = array();
    $group_index = 0;
    $group_size = 0;
    foreach ($zip_paths as $src => $dest) {
        $file_size = filesize($src);
        if ($group_size + $file_size <= $suggested_max_bytes) {
            $group_size += $file_size;
        } else {
            $zips = _pugpig_package_create_chunked_zip($zips, $partname, $filename, $group_index, $tmp_path, $real_path, $group, $zip_base_url);
            $group = array();
            $group_index++;
            $group_size = $file_size;
        }
        $group[$src] = $dest;
        if ($verbose) {
            _print_immediately("<strong>{$partname} group {$group_index}</strong>: size [{$group_size}] after adding [{$src}] <br>");
        }
    }
    $zips = _pugpig_package_create_chunked_zip($zips, $partname, $filename, $group_index, $tmp_path, $real_path, $group, $zip_base_url);
    if (count($zips) == 0) {
        _print_immediately('<em>No assets to be zipped.</em><br />');
    }
    return $zips;
}