如何使用缓存::与HttpSocket-记>后的CakePHP
我想缓存HttpSocket->post
调用的CakePHP 2如何使用缓存::与HttpSocket-记>后的CakePHP
我打电话以下代码:
$content = Cache::remember($key, function() use ($rateUrl, $xml, $uid) {
App::uses('HttpSocket', 'Network/Http');
$HttpSocket = new HttpSocket(array('ssl_verify_peer' => false));
return $HttpSocket->post($rateUrl, $xml->asXML(), array(
'header' => array(
'Content-Type' => 'text/xml',
'RestUid' => $uid,
)
));
});
但我发现了这个错误:
The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "HttpSocketResponse" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition
不要任何人知道的方式如何使用HttpSocket
类的匿名函数或致电CakePHP中或以其他方式?
由于错误消息说,你必须
[...] ensure that the class definition "HttpSocketResponse" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition
类定义为HttpSocketResponse
类型的serilaized对象不可用时,它已经被反序列化,这样的事情就不会工作。或者调用Cache::remember()
之前添加对应App::uses
语句,以便CakePHPs自动加载机可以加载所需的类定义
App::uses('HttpSocketResponse', 'Network/Http');
$content = Cache::remember(/* ... */);
或切换到使用作曲家,使得所需的类可以没有任何App::uses()
呼叫自动载入。或者,也可以使用unserialize_callback_func
ini指令来定义加载所需类定义的回调。
也
我尝试这样做,但didn't看到工作。 –