hprose / hprose-php Goto Github PK
View Code? Open in Web Editor NEWHprose is a cross-language RPC. This project is Hprose 3.0 for PHP
License: MIT License
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP
License: MIT License
我注意到是由于 Hprose\Future 中 100行~101行
if (($value !== NULL) and is_object($value) or is_string($value)) {
if (method_exists($value, 'then')) {
导致的
这是一个很棒的设计 但我觉得yaf 中的自动载入也是合理的
能否把 or is_string($value) 去掉
PHP Fatal error: Uncaught Exception: 405: Method Not Allowed
使用如下代码时,会报错,服务端使用nginx加了一个重定向wus/v1/ => public/index.php?version=v1
$client = Client::create('http://xxxx/wus/v1/', false);
$client->xxx();
不知道怎么处理?
Hprose的PHP序列化会将长度为1的字符串序列化为UTF8 Char,而C++的客户端无法把UTF8 Char反序列化为string。
最近项目使用hprse tcp server 后,server 进程不怎么稳定,总是每个两三天客户端就调用不了服务端的方法,登陆到服务器查看server 进程没什么异常,进程依然处于正常监听状态。奇怪的事,杀死server 进程,再重启进程,一切又正常了,这个问题困绕了我很久了,会不会是因为程序中使用exit die之类?或者是其他的问题?请赐教,非常感谢!
PHP框架 Yaf
服务器端:
<?php
class IndexController extends Rpc {
/**
* UserController::init()
*
* @return void
*/
public function init() {
parent::init();
Yaf_Dispatcher::getInstance()->disableView();
}
public function indexAction(){}
public function abcFunc($num) {//默认Action
return 'Hello,'.$num;
}
public function adFunc($a){
$a = '**';
$c = 'Hello';
$b = array('asf','Hello','asdf','**');
return $b;
}
}
客户端:
<?php
use Hprose\Client;
class IndexController extends Yaf_Controller_Abstract {
protected $web = '';
public function init(){
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
$rpc = $config->get("rpc");
Yaf_Registry::set("rpc", $rpc);
$this->web = Client::create($rpc->host . 'index', false);
}
public function indexAction() {//默认Action
$a = $this->web->abcFunc(1);
var_dump($a);
exit;
//$a = "Hello World";
$this->getView()->assign("content", $a);
}
public function aaAction(){
$a = $this->web->aaFunc();
var_dump($a);
exit;
}
}
?>
问题:
服务端 修改 返回的变量 当为 $a
的时候,报错如下:
Yaf_Loader::autoload(): Failed opening script E:\xampp\htdocs\blog/application/\library\**.php: No such file or directory
当为$c
时,报错如下:
Yaf_Loader::autoload(): Failed opening script E:\xampp\htdocs\blog/application/\library\Hello.php: No such file or directory
联系QQ:
[email protected]
当服务有多个返回值时,同步调用时,php怎么接收多个返回值?
当调用地址类似 http://127.0.0.1
useService方法调用的parse_url不会解析出path成员,同样的地址http://127.0.0.1/
不会造成此错误,加个isset()判断吧。
异常栈如下
Exception: iconv(): Detected an illegal character in input string in /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php:368
Stack trace:
#0 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(470): Hprose\Client->decode('Es54"iconv(): D...', Array, Object(stdClass))
#1 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(482): Hprose\Client->syncInvokeHandler('updateUserInfo', Array, Object(stdClass))
#2 /home/work/app/vendor/hprose/hprose/src/Hprose/HandlerManager.php(40): Hprose\Client->invokeHandler('updateUserInfo', Array, Object(stdClass))
#3 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(598): Hprose\HandlerManager->Hprose\{closure}('updateUserInfo', Array, Object(stdClass))
#4 /home/work/app/vendor/hprose/hprose/src/Hprose/Client.php(423): Hprose\Client->invoke('updateUserInfo', Array)
#5 /home/work/app/api/modules/user/controllers/InfoController.php(205): Hprose\Client->__call('updateUserInfo', Array)
#6 [internal function]: api\modules\user\controllers\InfoController->actionUpdate()
#7 /home/work/app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /home/work/app/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#9 /home/work/app/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('update', Array)
#10 /home/work/app/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction('user/info/updat...', Array)
#11 /home/work/app/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /home/work/app/api/web/index.php(16): yii\base\Application->run()
#13 {main}
Exception: Success in /home/share/cc/vendor/hprose/hprose/src/Hprose/Swoole/Socket/Client.php:139
“Hprose 客户端” 一节提到了 onError 事件和 onFailswitch 事件,但是并没有讲如何注册该事件。
另外,关于“onError 事件”有这样一句描述:“当客户端采用回调方式进行调用时,并且回调函数没有参数,如果发生异常,该事件会被调用”,什么叫“回调函数没有参数”,没有设置参数?没有传回参数?,这里的参数指的是 callback 函数的 $args 形参还是整个 callback 函数的参数?
请问如何发jsonrpc的通知呢,并且不等待返回结果
Fatal error: Uncaught Exception: Wrong Response:
HTTP/1.1 200 OK
Server: nginx/1.10.0
Date: Thu, 16 Nov 2017 00:44:51 GMT
Content-Type: text/plain;charset=UTF-8
Content-Length: 2172
Connection: keep-alive
X-Powered-By: PHP/7.1.9
Set-Cookie: PHPSESSID=dbcu4en8r14a2251gldpfivo49; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Rm2{s4"code"s3"200"s4"data"m9{s5"total"i122;s8"per_page"i10;s12"current_page"1s9"last_page"i13;s13"next_page_url"s8"/?page=2"s13"prev_page_url"ns4"from"1s2"to"i10;r3;a10{m13{s2"id"i176;s2"ip"s15"180.173.234.115"s4"uuid"s12"zhangziliang"s6"shared"s3"yes"s6"showed"1s4"href"s28"https://sspai.com/post/33299"s4"time"ns11"description"s44"通过终端命令改变 Launchpad 中应用图标的大小丨一日一技 · Mac - 少数派"s8"extended"es3"tag"es4"hash"ns4"meta"ns11"update_time"i1510706688;}m13{r16;i175;r17;r18;r19;r20;r21;r22;r23;1r24;s18"https://wxvip.org/"r26;nr27;s9"wxvip.org"r29;er30;s9"wechat wx"r31;nr32;nr33;i15106 in /Users/ziziliang/Google 云端硬盘/alfred/Alfred.alfredpreferences/workflows/user.workflow.BB9BF069-D107-4B0F-9034-2FAFA2F39327/vendor/hprose/hprose/src/Hprose/Client.php on line 374
new \Hprose\Http\Client($uri, false)创建了一个客户端,但发现请求是post方式发送的,问题是post请求在框架中是要签名认证的,所以有以下两点疑问
1.$this->client->invoke($name, $param)这样调用远程方法 如何带上签名,并且在远程方法$_POST[‘签名’]有值
2.获取改变请求方式为GET?
use Hprose\Client;
$client = Client::create('http://127.0.0.1:9999/', false);
var_dump($client->hello("world"));
$inputFileName='/nfs_file/sites/sys'.'/m/pingan/excel/8m.xlsx';//$_SERVER['DOCUMENT_ROOT']解析一个8M的excel
print_r($client->readExcel($inputFileName,0,68964,5));
echo "sss";die;
thinkphp框架 有 扩展 能否加入官方,并提供示列和文档
...
$server = new HproseSwooleServer("tcp://127.0.0.1:1504");
$server->setErrorTypes(E_ALL);
$server->setDebugEnabled();
$server->add(new TestModel(),'test');
...
[server]# php hprose_swoole_tcp.php
PHP Warning: array_diff(): Argument #1 is not an array in
hprose-php/Hprose/Service.php on line 330
PHP Warning: Invalid argument supplied for foreach() in
hprose-php/Hprose/Service.php on line 432
PHP Warning: Invalid argument supplied for foreach() in
hprose-php/Hprose/Service.php on line 442
对象添加了别名会又问题,
客户端调用找不到方法 Can't find this function TestModel_one().
php http_server.php 怎么直接就返回值了木有监听了?
PHPUnit_Framework_TestCase no longer works with PhpUnit 6.0+
PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found
hprose 中http服务结合tp5怎么使用,我弄不出来,客户端老是报错(Wrong Response)
classA.php
<?php
namespace name_A{
class Test_1 {
public $string = 'thisIsAString';
public $double = 12.0123838434893;
public $int = 1;
}
}
test code1:
$objTest1 = new name_A\Test_1();
$data = \Hprose\Formatter::serialize($objTest1);
echo $data,"\n";
//c13"name_A_Test_1"3{s6"string"s6"double"s3"int"}o0{s13"thisIsAString"d12.012383843489;1}
test code2:
$data = 'c13"name_A_Test_1"3{s6"string"s6"double"s3"int"}o0{s13"thisIsAString"d12.012383843489;1}';
var_dump(\Hprose\Formatter::unserialize($data));
/*
output:
class stdClass#5 (3) {
public $string =>
string(13) "thisIsAString"
public $double =>
double(12.012383843489)
public $int =>
int(1)
}
*/
namespace tag "" was replace by "" what cause true class lost.
i think use "\t" or "\n" to instead of "" in full class name, and it would be better ?
and there is any way to resolve it ?
and & i found java did this too.
in ClassUtils.java
public final static String getClassAlias(Class<?> type) {
String className = HproseClassManager.getClassAlias(type);
if (className == null) {
className = type.getName().replace('.', '_').replace('$', '_');
HproseClassManager.register(type, className);
}
return className;
}
PHP Fatal error: Uncaught exception 'Exception' with message '28: Operation timed out after 31013 milliseconds with 0 out of -1 bytes received' in
158 function($reason) use ($index, &$reasons, &$n, $reject) {
159 $reasons[$index] = $reason;
160 if (--$n === 0) {
161 $reject();
162 }
163 }
代码都是直接从readme里面取的,稍微调整了一下,server正常,client报错了
server
<?php
require_once('hprosesrc\Hprose.php');
function hello($name) {
return 'Hello ' . $name;
}
$server = new HproseHttpServer();
$server->addFunction('hello');
$server->start();
client
<?php
require_once('hprosesrc\Hprose.php');
$client = new HproseHttpClient('http://127.0.0.1/helloserver.php');
echo $client->hello('World');
错误提示
Object of class Hprose\Future could not be converted to string
环境是windows php5.4.16
server启动用,引入了A.php文件,后面再改这个A.php文件,不会自动reload这个改后文件。有没有现在的reload?或解决方案?现在的处理是重新启动服务器
如题:
RPC场景下,如何从客户端发送cookie到服务端?
socket_import_stream() expects parameter 1 to be resource, boolean given in
这是什么问题呢? #
class Hello
{
public function say($name)
{
return 'Hello '.$name;
}
}
use Hprose\Socket\Server;
$server = new Server("tcp://127.0.0.1:8000");
$server->add((new Hello()));
$server->debug = true;
$server->start();
想在客户端调用服务端的时候统一加上token
$settings = new InvokeSettings(array('userdata' => ['token' => $userData['token']]));
$client->hello($settings);
在服务端无法收到userdata
$this->server->addInvokeHandler(function ($name, array &$args, \stdClass $context, \Closure $next) {
//$context中没有userdata
})
require_once "vendor/autoload.php";
use Hprose\Http\Server;
function hello($name) {
return "Hello " . $name;
}
$server = new Server();
$server->addFunction("hello");
$server->start();
require_once "vendor/autoload.php";
use Hprose\Http\Client;
use Hprose\InvokeSettings;
use Hprose\ResultMode;
$client = new Client('http://order.local/s.php', false);
echo $client->hello("docker", new InvokeSettings(array('mode' => ResultMode::Normal)));
不通,可能是哪错了?服务器地址正式环境可用
如果一个方法,返回值是 一个数据对象 ModelA $a,它的一个属性 还是这个类 ModelA 构成的数据对象 $b, 那么这个返回结果在客户端就无法解析,报错为
Unexpected serialize tag '{' in stream
实例代码如下:
Server:
public function testConnection()
{
$label = Label::find(1);
$label->child = Label::find(2);
return $label;
}
请问应当如何解决。
PHP Fatal error: Cannot redeclare Hprose\nextTick() (previously declared in /Users/fucongcong/products/HP/vendor/hprose/hprose/src/Hprose/functions.php:38) in /Users/fucongcong/products/HP/vendor/hprose/hprose/src/Hprose/functions.php on line 40
在laravel中服务端调用出错提示:
Argument func must be callable.
`namespace App\Http\Controllers;
use Hprose\Http\Server;
use Illuminate\Http\Request;
class TestController extends Controller
{
public function index(){
$server = new Server();
$server->addFunction('hello',$this);
$server->start();
}
public function hello(){
return "Hello";
}
}`
$buffer = @fread($stream, $remaining);
在7.1.5下运行 没有任何反应 也不报错
php 的 hprose server,
我在关闭报错误(display_error:Off)之后会报一个http code=500的内部错误,但是我打开报错误就是正常的,而且我这边看日志确实没有啥错误。
前几天也出现了,我把代码全部删除,重新clone一份又正常了,搞不太懂,是不是hprose内部会缓存代码呢?之前我修改了一些server的代码,客户端去调用都会缓存一会儿,每次都重启了php都没有用。
hprose/hprose/src/Hprose/Http/Client.php(279): Hprose\Http\Client->getContents('HTTP/1.1 500 In...', Object(stdClass))
hprose/hprose/src/Hprose/Http/Client.php(296): Hprose\Http\Client->syncSendAndReceive('Cs4"post"a1{m3{...', Object(stdClass))
hprose/hprose/src/Hprose/Client.php(49 in /home/wwwroot/demo.gateapi.cn/vendor/hprose/hprose/src/Hprose/Http/Client.php on line 266
可以考虑支持laravel么?
Fatal error: Uncaught Error: Class 'swoole_http_server' not found in /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Http/Server.php:27 Stack trace: #0 /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Server.php(58): Hprose\Swoole\Http\Server->__construct('127.0.0.1', 10000, 'SWOOLE_PROCESS') #1 /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Server.php(90): Hprose\Swoole\Server->init_server('http://127.0.0....') #2 /Library/WebServer/Documents/hprose-php/demo/server.php(13): Hprose\Swoole\Server->__construct('http://127.0.0....') #3 {main} thrown in /Library/WebServer/Documents/hprose-php/src/Hprose/Swoole/Http/Server.php on line 27
Installs: hprose/hprose-php:dev-master b05f780
composer 安装只能更新到这个提交,更新不到2.0.30。是什么原因?
strlen(iconv('UTF-8', 'UTF-16LE', $s)) >> 1;
上面这个算长度的,某些情况下会为0。命令行执行为0,浏览器执行为正确的值。
导致请求的时候失败。
请问下使用的时候,客户端参数传输错误导致服务端异常退出,try cactch 无法捕获异常,onSendError也处理不了,请问下有什么解决方案吗
require __DIR__.'/../vendor/autoload.php';
use Hprose\Swoole\Server;
function a($b, $c) {
echo $b;
echo $c;
}
$server = new Server("tcp://0.0.0.0:1314");
$server->setDebugEnabled(true);
dump($server->isDebugEnabled());
$server->addFunction('a');
$server->onSendError = function ($error, \stdClass $context) {
dump($error->getMessage());
return true;
};
$server->start();
$client = \Hprose\Client::create('tcp://127.0.0.1:1314', false);
return $client->a(['name' => 'xz'], new InvokeSettings(array('mode' => ResultMode::Normal)));
现在的HproseSwoole等Server都不能直接设置各种回调函数,比如onStart,onWorkerStart,onTask等,这样限制了不少功能,能否在下一版本的Hprose中放出来,或者我这边做好提一个PR?
如题,像swoole的server是可以设置参数"daemonize" => true
,那么hprose呢?
如题
src/Hprose/Socket/Transporter.php
private function write($stream, $request) {
$buffer = $this->appendHeader($request);
$length = strlen($buffer);
while (true) {
$sent = @fwrite($stream, $buffer, $length);
if ($sent === false) {
return false;
}
if ($sent < $length) {
$buffer = substr($buffer, $sent);
$length -= $sent;
}
else {
return true;
}
}
}
fwrite 写数据时加了@
如果用 set_error_handler() 设定了自定义的错误处理函数,仍然会被调用,但是此错误处理函数可以(并且也应该)调用 error_reporting(),而该函数在出错语句前有 @ 时将返回 0。 --php手册
如果fwrite出现异常,将会出现死循环
否则调用 Completer 的 isCompleted() 方法就出错了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.