我的 PHP 脚本将 Retina 图像服务器提供给具有高分辨率显示器的设备通常会给出错误 500,我不知道为什么。这是我的脚本:
<?php
/**********************/
/* SETTING VARS */
/**********************/
define('CACHE_TIME', 24*60*60);
$document_root = $_SERVER['DOCUMENT_ROOT'];
$source_file = $document_root."/".$_GET['img'];
$source_ext = strtolower(pathinfo($source_file, PATHINFO_EXTENSION));
$retina_file = pathinfo($source_file, PATHINFO_DIRNAME).'/'.pathinfo($source_file, PATHINFO_FILENAME).'@2x.'.pathinfo($source_file, PATHINFO_EXTENSION);
$cache_directive = 'must-revalidate';
$dpr = $_COOKIE['dpr'];
/*********************/
/* WHICH FILE? */
/*********************/
if($dpr == 2){
if(file_exists($retina_file)){
$serve_file = $retina_file;
}else{
$serve_file = $source_file;
}
}else{
if(file_exists($source_file)){
$serve_file = $source_file;
}else{
$serve_file = $retina_file;
}
}
/**********************/
/* SERVING FILE */
/**********************/
if (!file_exists($serve_file)) {
header('HTTP/1.1 404 Not Found', true);
exit();
}
// Send cache headers
header("Cache-Control: private, {$cache_directive}, max-age=".CACHE_TIME, true);
date_default_timezone_set('GMT');
header('Expires: '.gmdate('D, d M Y H:i:s', time()+CACHE_TIME).' GMT', true);
$etag = '"'.filemtime($serve_file).fileinode($serve_file).'"';
header("ETag: $etag", true);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && ($_SERVER['HTTP_IF_NONE_MATCH']) === $etag) {
// File in cache hasn't change
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($serve_file)).' GMT', true, 304);
exit();
}
// Send image headers
if (in_array($source_ext, array('png', 'gif', 'jpeg', 'bmp'))) {
header("Content-Type: image/".$source_ext, true);
}
else {
header("Content-Type: image/jpeg", true);
}
header('Content-Length: '.filesize($serve_file), true);
// Send file
readfile($serve_file);
exit();
?>
这是我的错误日志:
[13-Feb-2013 06:51:10 America/Chicago] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/pdo_sqlite.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/pdo_sqlite.so: cannot make segment writable for relocation: Cannot allocate memory in Unknown on line 0
[13-Feb-2013 06:51:42 America/Chicago] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
[13-Feb-2013 08:23:21 America/Chicago] PHP Fatal error: Out of memory (allocated 262144) (tried to allocate 261900 bytes) in Unknown on line 0
[13-Feb-2013 08:55:36 America/Chicago] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
[16-Feb-2013 04:24:10 America/Chicago] PHP Fatal error: Out of memory (allocated 262144) (tried to allocate 261900 bytes) in Unknown on line 0
错误发生在页面中的随机图像上,它总是不同的。有时页面甚至在我的图像上加载时没有任何错误。