高解像度ディスプレイを備えたデバイスに網膜画像をサーバーするための私のPHPスクリプトでは、エラー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
エラーはページ内のランダムな画像で発生します。常に異なる画像です。画像にエラーが発生することなくページが読み込まれることもあります。