Heim >Backend-Entwicklung >PHP-Tutorial >Yar 报错 Yar_Client_Protocol_Exception

Yar 报错 Yar_Client_Protocol_Exception

WBOY
WBOYOriginal
2016-06-06 20:27:312533Durchsuche

根据鸟哥博客上Yar的介绍,书写示例时,报Yar_Client_Protocol_Exception错误,Google和Baidu都没有查到解决办法,各位大侠有没有知道的呢?

yarServer.php

<code>class API {
    public function hello ($param = '')
    {
        return $param;
    }
    protected function hello2 ()
    {
    }
}
$service = new Yar_Server(new API());
$service->handle();</code>

yarClient.php

<code><?php $client = new Yar_Client('http://yar.demo.com/yarServer.php');
//Set timeout to 1s
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);
//Set packager to JSON
$client->SetOpt(YAR_OPT_PACKAGER, "json");
$result = $client->hello('zhangsan');</code>

错误详情

<code>Warning: [Debug Yar_Client 15:48:0.982003]: 2204859703: call api 'hello' at (r)'http://yar.demo.com/yarServer.php' with '1' parameters in /home/liuruntao/YarRPC-Demo/public/yarClient.php on line 10
Warning: [Debug Yar_Client 15:48:0.982082]: 2204859703: pack request by 'JSON', result len '53', content: '{"i":2204859703,"m":"hello","p":' in /home/liuruntao/YarRPC-Demo/public/yarClient.php on line 10
Fatal error: Uncaught exception 'Yar_Client_Protocol_Exception' with message 'malformed response header '
Warning: [Debug Yar_Server 15:4'' in /home/liuruntao/YarRPC-Demo/public/yarClient.php:10
Stack trace:
#0 /home/liuruntao/YarRPC-Demo/public/yarClient.php(10): Yar_Client->__call('hello', Array)
#1 /home/liuruntao/YarRPC-Demo/public/yarClient.php(10): Yar_Client->hello('zhangsan')
#2 {main}
  thrown in /home/liuruntao/YarRPC-Demo/public/yarClient.php on line 10</code>

回复内容:

根据鸟哥博客上Yar的介绍,书写示例时,报Yar_Client_Protocol_Exception错误,Google和Baidu都没有查到解决办法,各位大侠有没有知道的呢?

yarServer.php

<code>class API {
    public function hello ($param = '')
    {
        return $param;
    }
    protected function hello2 ()
    {
    }
}
$service = new Yar_Server(new API());
$service->handle();</code>

yarClient.php

<code><?php $client = new Yar_Client('http://yar.demo.com/yarServer.php');
//Set timeout to 1s
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);
//Set packager to JSON
$client->SetOpt(YAR_OPT_PACKAGER, "json");
$result = $client->hello('zhangsan');</code>

错误详情

<code>Warning: [Debug Yar_Client 15:48:0.982003]: 2204859703: call api 'hello' at (r)'http://yar.demo.com/yarServer.php' with '1' parameters in /home/liuruntao/YarRPC-Demo/public/yarClient.php on line 10
Warning: [Debug Yar_Client 15:48:0.982082]: 2204859703: pack request by 'JSON', result len '53', content: '{"i":2204859703,"m":"hello","p":' in /home/liuruntao/YarRPC-Demo/public/yarClient.php on line 10
Fatal error: Uncaught exception 'Yar_Client_Protocol_Exception' with message 'malformed response header '
Warning: [Debug Yar_Server 15:4'' in /home/liuruntao/YarRPC-Demo/public/yarClient.php:10
Stack trace:
#0 /home/liuruntao/YarRPC-Demo/public/yarClient.php(10): Yar_Client->__call('hello', Array)
#1 /home/liuruntao/YarRPC-Demo/public/yarClient.php(10): Yar_Client->hello('zhangsan')
#2 {main}
  thrown in /home/liuruntao/YarRPC-Demo/public/yarClient.php on line 10</code>

报错的原因找到了,只要把yar的debug功能关掉就可以!

<code>vim php.ini

yar.debug=0 ;或者注释掉</code>

这样是可以解决上述问题,楼主是否知道为啥会报这个warning,为啥呢?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn