手册以及网上众多的文章,都忽略了一个问题,让我抓狂了一晚上。
PHP5用SOAP扩展写的server,很简单,用PHP5调用,一点问题没有;
偏偏有个PHP4的系统,需要调用SOAP,因为没有扩展可装,只能用nusoap;
于是问题就出现了:nusoap调用成功,接收返回值的时候一直报错,说content type不是xml,是html的,不予接受。
查手册和资料未果,把nusoap的代码看了一遍,发现他有个地方在判断http header的类型,如果不是text/xml的,就拒绝解析返回值。
然后,我在调用Soap Server之前,加了一句:
header(‘Content-type: text/xml’);
世界就清净了。
如果不加这一句强制指定content type,默认是PHP SOAP是按text/html输出的,应该算是个bug?也许。
Zend_Gdata_Photos_UserEntry, 281行
public function getGphotoQuotaCurrent()
{return $this->_gphotoThumbnail; }
正确的应该是:
return $this->_gphotoQuotaCurrent;
检查了一下,最新发布的1.7.0也有此bug,已经提交给Zend了。
[php]
<?php
require_once(‘Zend/Gdata.php’);
require_once(‘Zend/Gdata/Query.php’);
require_once(‘Zend/Gdata/ClientLogin.php’);
//向 Blogger发送文章,可自定义Tag
class Blogger{
private $gdClient;
private $blogID;
public function __construct($mail, $password, $blogID){
$service = ‘blogger’;
$client = Zend_Gdata_ClientLogin::getHttpClient($mail, $password, $service);
$this->gdClient = new Zend_Gdata($client);
$this->blogID = $blogID;
}
public function printAllBlogs(){
$query = new Zend_Gdata_Query(‘https://www.blogger.com/feeds/default/blogs’);
$feed = $this->gdClient->getFeed($query);
$this->printFeed($feed);
}
public function printFeed($feed){
$i = 0;
foreach($feed->entries as $entry) {
print_r (split(‘-’, $entry->id->text));
$i++;
}
}
public function createPublishedPost($title=’Hello, world!’, $content=’I am blogging on the internet.’, $category= ”, $publish){
$uri = ‘https://www.blogger.com/feeds/’ . $this->blogID . ‘/posts/default’;
$entry = $this->gdClient->newEntry();
$entry->title = $this->gdClient->newTitle($title);
$entry->content = $this->gdClient->newContent($content);
$entry->published = $this->gdClient->newPublished($publish);
if(preg_match(‘/,/s’,$category)){
$categorys = explode($category,’,');
}else{
$categorys[] = $category;
}
$labels = array();
foreach ($categorys as $key =>$value){
$labels[] = new Zend_Gdata_App_Extension_Category($value, ‘http://www.blogger.com/atom/ns#’);
}
$entry->setCategory($labels);
$entry->content->setType(‘text’);
$createdPost = $this->gdClient->insertEntry($entry, $uri);
$idText = split(‘-’, $createdPost->id->text);
$newPostID = $idText[2];
return $newPostID;
}
}
[/php]
js传递中文时会使用escape进行编码,所以,接收到值以后要decode一下就能还原出中文了
function js_unescape($str)
{
$ret = ”;
$len = strlen($str);
for ($i = 0; $i < $len; $i++)
{
if ($str[$i] == ‘%’ && $str[$i+1] == ‘u’){
$val = hexdec(substr($str, $i+2, 4));
if ($val < 0×7f) $ret .= chr($val);
else if($val < 0×800) $ret .= chr(0xc0|($val>>6)).chr(0×80|($val&0×3f));
else $ret .= chr(0xe0|($val>>12)).chr(0×80|(($val>>6)&0×3f)).chr(0×80|($val&0×3f));
$i += 5;
}
else if ($str[$i] == ‘%’)
{
$ret .= urldecode(substr($str, $i, 3));
$i += 2;
}
else $ret .= $str[$i];
}
return $ret;
}
写代码写久了,有的习惯就养成了
比如敲了一个大括号,顺手肯定会把另外一半也敲上
写php也写了有段时间了,一直都是<?php开头 ,然后顺手敲上 ?> 结尾
今天看Zend frameword的文档,才突然发现,原来
对于只包含有 PHP 代码的文件,结束标志(”?>”)是不允许存在的,PHP自身不需要(”?>”), 这样做, 可以防止它的末尾的被意外地注入空白并显示输出。
原来如此,之前在看Zf的例子代码的时候就在奇怪为什么没有?>结尾,一直没去好好想,现在刚明白
回头去修改类代码。
看似很简单,其实不然
使用的当的话,几乎可以精确控制到页面操作的每个细节
非常灵活
只是Zend的文档写的太不详细了,害我琢磨了很久
网站的项目里,Cache被大量使用,但是Cache的位置却一直让人很迷糊。
统计了我自己的几个项目里Cache的位置:
1、数据读取后立即缓存:
这种方式是最容易理解的方式,既然是要经常用到的数据,就先缓存,免得再重复的读取。
如果应用程序的层次简单,这种方式很好用。
2、数据操作层不缓存任何数据,在逻辑层缓存:
数据操作类里,可能会涉及到多表的操作,从各个表里取出数据,经过计算整理之后返回值。
这种方式,各个数据库操作读取的数据其实都是临时性的数据,如果都缓存起来,会浪费不必要的内存空间,因为我们需要的仅仅是最后的结果而已。
3、数据层和应用层都不缓存数据,页面展示层缓存:
在Web程序中,数据库的操作最终被反映到页面进行展示,数据操作和应用层的整合处理,都可以看做临时数据;
只需要把页面的各个部分按不同的策略缓存就行了,这样连应用层的计算时间都节省了。
以上三种Cache的方式,各有优缺点,不过通过我自己的实践发现,第一种Cache方式最好不要使用,后两种,需要搭配使用。
最近评论