我本来使用WURFL很好,但是突然抛出了这个错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65484 bytes) in /var/wwwlibs/vnd/WURFL/lib/CustomDevice.php on line 118我在网上找到了一些关于Tera-WURFL的东西,但(afaik)我并没有使用这些东西,而只是从sourceforge下载的版本。有人建议更新SimpleXML,但我只是不明白为什么WURFL会走得太远。
我的包装类如下:
<?php
namespace vnd\WURFL;
use \WURFL_Configuration_InMemoryConfig;
use \WURFL_WURFLManagerFactory;
/**
* File: WURFL_bootstrap.php
* Sets up and readies the WURFL library for platform and browser detection.
*/
require_once 'WURFL/lib/Application.php';
// ----- WURFL constants ------ //
define('WURFL_ROOT', dirname(__FILE__).'/');
# Directories
define('WURFL_RESOURCES_DIR', WURFL_ROOT.'resources/');
define('WURFL_PERSISTENCE_DIR', WURFL_RESOURCES_DIR.'storage/persistence');
define('WURFL_CACHE_DIR', WURFL_RESOURCES_DIR.'storage/cache');
class WURFLBootstrap extends WURFL_Configuration_InMemoryConfig {
const WURFL_WATCH_MODE = "performance";
const WURFL_VERSION = '2.3.3';
const WURFL_CACHE_EXP = 36000;
# Our WURFL Manager
private $_manager;
# Our device where the capabilities lie
private $_device;
public function __construct(){
$zipPath = $this->getPath();
if(!is_file($zipPath))
die($zipPath.' is not a valid file.');
if(!is_dir(WURFL_PERSISTENCE_DIR) || !is_dir(WURFL_CACHE_DIR))
die(WURFL_PERSISTENCE_DIR.' or '.WURFL_CACHE_DIR.' are not valid directories.');
$this->wurflFile($zipPath);
$this->matchMode(self::WURFL_WATCH_MODE);
$this->persistence('file', array('dir' => WURFL_PERSISTENCE_DIR));
$this->cache('file', array('dir' => WURFL_CACHE_DIR, 'expiration' => self::WURFL_CACHE_EXP));
// Automatically reload the WURFL data if it changes
$this->allowReload(true);
// Create a WURFL Manager Factory from the WURFL Configuration
$wurflManagerFactory = new WURFL_WURFLManagerFactory($this);
// Create our factory and start the process.
$this->_device = $wurflManagerFactory->create()->getDeviceForHttpRequest($_SERVER);
}
/**
* Returns the path to our ZIP file
*/
private function getPath(){
return WURFL_RESOURCES_DIR.'/wurfl-'.self::WURFL_VERSION.'.zip';
}
/**
* Seeing as this is a wrapper class, any calls to our $wflManager (or whatever
* we happened to be assigned to) should be passed on to the actual
* manager object where all the goodies lie.
*
*/
public function __call($name, $arguments){
//return $this->device->$name($arguments);
}
public function getDevice(){
return $this->_device;
}
}运行它的计算机是一台旧笔记本电脑,所以它没有存储在内存中,但这是怎么回事?我删除了所有可能导致内存过度分配的东西,但到目前为止,WURFL似乎就是不想运行。
我还尝试清除缓存和持久性目录,并再次运行它,但没有成功。
我正在考虑的一件事是使用XML configuration类,而不是WURFL_Configuration_InMemoryConfig (根据名称,我假设它将所有内容都存储在内存中,至少是暂时的,因此发生了崩溃),但我很好奇为什么突然抛出了这个错误。
发布于 2013-04-03 06:45:10
我不熟悉这个库,但一般来说,您可以通过registering a shutdown function并在那里打印最后一个错误来准确地找出哪里出了问题。
在脚本的开始处(即错误发生之前)添加以下代码:
function my_shutdown_function() {
echo "SHUTDOWN!\n";
$err = error_get_last();
if($err) {
print_r($err);
// optionally, if you want a stack trace:
$ex = new Exception;
print_r($ex->getTraceAsString());
}
}
register_shutdown_function('my_shutdown_function');如果愿意,您可以使用set_error_handler和set_exception_handler获得类似的乐趣,尽管这两个工具永远不会捕获致命错误(以及其他失败)。
https://stackoverflow.com/questions/15774989
复制相似问题