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 />"); } }
function _pugpig_show_batch($rows, $file_warning_size_kb = 250, $file_warning_time_secs = 10) { echo "<table style='font-size:small;''>\n"; echo "<tr>"; echo "<th colspan='5'>Metrics</th>"; echo "<th colspan='2'>Cache Headers</th>"; echo "<th colspan='4'>Edge</th>"; echo "<th></th>"; echo "</tr>"; echo "<tr>"; echo "<th>HTTP</th>"; echo "<th>Time</th>"; echo "<th>Type</th>"; echo "<th>Size</th>"; echo "<th>Valid</th>"; echo "<th>Modified</th>"; echo "<th>Expires</th>"; echo "<th>Server</th>"; echo "<th>Encoding</th>"; echo "<th>Auth</th>"; echo "<th>Status</th>"; echo "<th>URL</th>"; echo "</tr>"; foreach ($rows as $key => $vals) { echo "<tr>"; $vals['h'] = _getHeadersFromString($vals['headers']); if (isset($vals['curl_info'])) { $http_code = $vals['curl_info']['http_code']; $http_code_style = ''; if ($http_code != 200) { $http_code_style = 'background:#ff6600'; } echo "<td style='{$http_code_style}'>{$http_code}</td>\n"; $time = $vals['curl_info']['total_time']; $percentage = $time / $file_warning_time_secs * 100; $barcolor = "lightblue"; if ($percentage > 100) { $barcolor = "orange"; } if ($percentage > 200) { $barcolor = "red"; } $time_style = "white-space: nowrap; background: -webkit-gradient(linear, left top,right top, color-stop({$percentage}%,{$barcolor}), color-stop({$percentage}%,white))"; echo "<td style='{$time_style}'>" . $vals['curl_info']['total_time'] . "</td>\n"; } else { echo "<td> - </td>\n"; echo "<td> - </td>\n"; } $content_type = ""; $content_type_style = ""; if (isset($vals['h']['content-type'])) { $content_type = $vals['h']['content-type']; } else { $content_type_style = 'background: pink'; } $char = pugpig_get_download_char($key, $content_type); echo "<td style='{$content_type_style}'>" . $char . "</td>"; $bytes = 0; if (file_exists($vals['file'])) { $bytes = filesize($vals['file']); } $percentage = $bytes / (1024 * $file_warning_size_kb) * 100; $barcolor = "lightblue"; if ($percentage > 100) { $barcolor = "orange"; } if ($percentage > 200) { $barcolor = "red"; } $size_style = "white-space: nowrap; background: -webkit-gradient(linear, left top,right top, color-stop({$percentage}%,{$barcolor}), color-stop({$percentage}%,white))"; echo "<td style='{$size_style}'>" . pugpig_bytestosize($bytes) . "</td>\n"; $error = pugpig_validate_file($vals['file'], $content_type); if (!empty($error)) { echo "<td style='background: pink'>{$error}</td>\n"; } else { echo "<td>Y</td>\n"; } if (isset($vals['h']['last-modified'])) { echo "<td>" . _ago(strtotime($vals['h']['last-modified']), 0, true) . " ago</td>\n"; } else { echo "<td style='background: pink'>?</td>\n"; } if (isset($vals['h']['expires'])) { echo "<td>in " . _ago(strtotime($vals['h']['expires']), 0, false) . "</td>\n"; } else { if (isset($vals['h']['etag'])) { echo "<td>eTag</td>\n"; } else { echo "<td style='background: pink'>?</td>\n"; } } $cache_layer = _pugpig_get_cache_layer($vals['h']); $cache_layer_style = ""; if (in_array($cache_layer, array('PPITC', 'AKAMAI', 'CLOUDFRONT'))) { $cache_layer_style = 'background:#6ce1c4'; } elseif (in_array($cache_layer, array('VARNISH'))) { $cache_layer_style = 'background:#66ccff'; } elseif (in_array($cache_layer, array('PHP'))) { $cache_layer_style = 'background:#b20047'; } echo "<td style='{$cache_layer_style}'>{$cache_layer}</td>\n"; $content_encoding = ""; $content_encoding_style = ''; if (isset($vals['h']['content-encoding'])) { $content_encoding .= $vals['h']['content-encoding'] . " "; } if (isset($vals['h']['transfer-encoding'])) { $content_encoding .= $vals['h']['transfer-encoding'] . " "; } if (in_array($content_encoding, array('gzip'))) { $content_encoding_style = 'background:#6ce1c4'; } echo "<td style='{$content_encoding_style}'>{$content_encoding}</td>\n"; if (isset($vals['h']["x-pugpig-entitlement"])) { echo "<td>LOCKED</td>\n"; } else { echo "<td>-</td>\n"; } $status = ""; if (isset($vals['h']["x-pugpig-status"])) { $status .= $vals['h']["x-pugpig-status"]; } echo "<td>{$status}</td>\n"; $suspect_style = pugpig_check_suspect_path($key) ? 'background:#ff6600' : ($char == 'f' ? 'background:#66ccff' : ''); echo "<td style=' {$suspect_style}'><a title='" . $vals['headers'] . "' target='_blank' href='{$key}'>" . pugpig_strip_domain($key) . "</a></td>\n"; echo "</tr>"; } echo "</table>\n"; }
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 />"); } }