Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 序列化对象并缓存它们的奇怪行为_Php_Zend Framework_Serialization_Zend Cache - Fatal编程技术网

Php 序列化对象并缓存它们的奇怪行为

Php 序列化对象并缓存它们的奇怪行为,php,zend-framework,serialization,zend-cache,Php,Zend Framework,Serialization,Zend Cache,我遇到了一个我似乎无法缩小范围的问题。在Zend Framework应用程序中,我使用Zend缓存缓存包含在自定义响应对象中的潮汐和天气数据。在最初创建数据时,一切正常。我序列化它并缓存它。然后,当我点击refresh并从缓存中提取数据时,我得到以下错误: 消息:无法将字符串解析为XML 堆栈跟踪: 0/home/cillosis/mysites/tidely/application/views/scripts/tides/location.phtml(38):simplexmlement->\

我遇到了一个我似乎无法缩小范围的问题。在Zend Framework应用程序中,我使用Zend缓存缓存包含在自定义响应对象中的潮汐和天气数据。在最初创建数据时,一切正常。我序列化它并缓存它。然后,当我点击refresh并从缓存中提取数据时,我得到以下错误:

消息:无法将字符串解析为XML

堆栈跟踪:

0/home/cillosis/mysites/tidely/application/views/scripts/tides/location.phtml(38):simplexmlement->\uu构造(“”)

1/home/cillosis/mysites/tidely/library/Zend/View.php(108):include(“/home/cillosis/…”)

2/home/cillosis/mysites/tidely/library/Zend/View/Abstract.php(888):Zend_View->_run('/home/cillosis/…)

这发生在我的视图中,我使用以下命令访问自定义“响应对象”中包含的XML:

<div class="data-box">

<h3>Current Weather</h3>
<hr>
<?php

// *** THIS IS LINE 38  ***                         
$weather_XML = new SimpleXMLElement($this->response->_weatherdata->weatherResults);
$params = $weather_XML->data->parameters;

$img_path = $params->{'conditions-icon'}->{'icon-link'};

echo("<img src='".$img_path."'>");

...
// Assign cache id
// Example query: "Chesapeake Bay Virginia"
$cache_id = 'request_results_' . $this->response->_querydata->query);
$cache_id = str_replace(' ', '_', $cache_id);
$cache_id = str_replace('-', '_', $cache_id);

// Check cache for this query
if ( ($results = $this->_cache->load($cache_id)) === false)
{
   // Cache not found, process request and generate response
   ...

   // Cache request output for specific query
   $serialized_data = serialize($this->response);
   $this->_cache->save($serialized_data, $cache_id);

   // Return processed request results
   return $this->response;
}
else
{
   // Return results from cache
   return unserialize($results);
}
我使用以下方法进行缓存和检索:

<div class="data-box">

<h3>Current Weather</h3>
<hr>
<?php

// *** THIS IS LINE 38  ***                         
$weather_XML = new SimpleXMLElement($this->response->_weatherdata->weatherResults);
$params = $weather_XML->data->parameters;

$img_path = $params->{'conditions-icon'}->{'icon-link'};

echo("<img src='".$img_path."'>");

...
// Assign cache id
// Example query: "Chesapeake Bay Virginia"
$cache_id = 'request_results_' . $this->response->_querydata->query);
$cache_id = str_replace(' ', '_', $cache_id);
$cache_id = str_replace('-', '_', $cache_id);

// Check cache for this query
if ( ($results = $this->_cache->load($cache_id)) === false)
{
   // Cache not found, process request and generate response
   ...

   // Cache request output for specific query
   $serialized_data = serialize($this->response);
   $this->_cache->save($serialized_data, $cache_id);

   // Return processed request results
   return $this->response;
}
else
{
   // Return results from cache
   return unserialize($results);
}
一旦我发出请求并将其缓存,则
$this->response
对象输出如下:

object(Tidely_ResponseData)65(7){{{{{{{u querydata}=>object(Tidely_querydata){66(9){{{{query}=>string(40)“bayou la batre密西西比湾阿拉巴马州”[“源”]=>string(15)“TidesController”[“请求类型”]=>string(3)“url”[“url\u组件”=>array(2){“州”=>string(7)“阿拉巴马州”[“位置”=>string(32)“密西西比河海湾”}[“返回类型”]=>字符串(4)“JSON”[“时间范围”]=>数组(2){[“开始”]=>对象(日期时间){64(3){[“日期”]=>字符串(19)”2012-04-05 18:06:51“[“时区类型”]=>int(3)“UTC”}[“结束”=>对象(日期时间){63(3){“日期”=>string(19)”时区(12:06:51”=>int(3)类型)[“时区”]=>string(3)“UTC”}[“hasError”]=>bool(false)[“用户消息”]=>NULL[“日志消息”]=>NULL}[“\u位置数据”]=>object(Tidely\u位置数据){80(31){[“位置id”]=>string(5)“18921”[“站名”=>string(33)“密西西比州巴特雷湾”[“站名”=>string(32)“密西西比湾之声”[”车站类型“]=>string(11)“从属”[“车站id”]=>string(7)“8739051”[“车站平面”]=>string(8)”+30.3717“[“车站长度”=>string(8)”-88.2750“[“车站高度偏移量高”]=>string(5)”*1.23“[“车站高度偏移量低”=>string(5)”*1.23“[“车站时间偏移量高”=>string(3)”112”[“车站时间偏移量低”=>2”“[”station\u ref\u station\u id”]=>string(7)“8760551”[”state\u id”]=>string(1)“1”[”state\u name”]=>string(7)“阿拉巴马州”[”state\u url\u name”]=>string(7)“阿拉巴马州”[”时区”=>string(2)“6”[”dst”=>string(1)“1”[”城市名称”=>string(14)“Bayou La Batre”[”城市邮编”=>string(5)“36509”[”城市”=>“-88.2467”[“邻接电台”]=>字符串(321)”a:10:{i:8739051;d:2.6562027890531361;s:7:“TEC4393”7.i:8735180;d:d:14.63778787875757575757575757577;i:8735180;d:14.637787575757575757575757575757575757575757575757575757575757575757575858585858577;d:8;i:2004;d:11.47484848484848484848483737444444444444444444444444444919;i:873707;i:2007;7;7;7;7.7878787878748;4.4141404040404040402828282828282828282828282828282828259932;32;32;32;32;i;i;i;i;i;i;i;i;i;i:2828282828282828282840404040404040404040404040404040404028282828多重结果“]=>string(0)“[“multipleCount”]=>int(0)[“hasMultiple”]=>bool(false)[“showStates”]=>bool(false)[“showLocations”]=>bool(false)[“hasError”]=>bool(false)[“userMessage”]=>NULL[“logMessage”=>NULL}[“tidedata”]=>object(Tidely#tidedata){68(6){“tideres”]=>NULL[“queryStart”]=>NULL[“queryStart”]=>NULL[>NULL[“query”=>NULL[][“userMessage”]=>NULL[“logMessage”]=>NULL}[“\u weatherdata”]=>object(Tidely\u weatherdata)#79(6){[“weatherResults”]=>string(6399)”气象预报2012-04-05T18:06:57Z气象发展实验室产品生成分公司http://www.weather.gov/ http://www.weather.gov/feedback.php 点1 k-p24h-n1-1 2012-04-05T08:00:00-05:00 2012-04-05T20:00:00-05:00 k-p24h-n1-2 2012-04-05T20:00-05:00 2012-04-06T09:00:00-05:00 k-p3h-n5-3 2012-04-05T13:00-05:00 2012-04-05T16:00:00-05:00 2012-04-05T19:00:00-05:00 2012-04-05T22:00-05:00 2012-04-06T01:00:00-05:00日最高气温81日最低气温79 74 69露点温度66 65 64 61风速12 11 13 14风向240 260 280 300 330相对湿度64 63 71 81天气类型、覆盖范围和强度条件图标http://forecast.weather.gov/images/wtf/tsra60.jpg http://forecast.weather.gov/images/wtf/nscttsra20.jpg “[“queryStart”]=>float(1333649211.6989)[“queryEnd”]=>float(1333649217.2038)[“hasError”]=>bool(false)[“userMessage”]=>NULL[“logMessage”]=>NULL}[“hasError”]=>bool(false)[“userMessage”]=>NULL[“logMessage”]=>NULL}

当我查看源代码时,“weatherResults”部分有XML,我不会复制和粘贴它,因为它相当长。下面是当我按refresh时发生的情况,它使用上述对象的缓存副本:

object(Tidely_ResponseData)65(7){{{{{querydata}=>object(Tidely_querydata){66(9){{{query}=>string(40)“bayou la batre密西西比湾阿拉巴马州”[“源”]=>string(15)“TidesController”[“请求类型”]=>string(3)“url”[“url\u组件”=>array(2){“州”=>string(7)“阿拉巴马州”[“位置”=>string(32)”密西西比州巴特尔湾海湾(bayou la batre Missississippi sound)}[“返回类型”]=>string(4)“JSON”[“时间范围”]=>array(2){[“开始”]=>object(DateTime){64(3){“date”]=>string(19)“2012-04-05 18:10:30”[“时区类型”]=>int(3)“UTC”}[“结束”=>object(DateTime){>63(3){“date”=>string(19)“时区类型”[]时区“]=>string(3)“UTC”}}[“hasError”]=>bool(false)[“userMessage”]=>NULL[“logMessage”]=>NULL}[“\u locationdata”]=>object(Tidely\u locationdata){67(31){[“location\u id”]=>string(0)”[“station\u name”]=>string(0)