Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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 推送器未定义属性:stdClass::$channels in Laravel Lumen_Php_Laravel_Lumen_Pusher - Fatal编程技术网

Php 推送器未定义属性:stdClass::$channels in Laravel Lumen

Php 推送器未定义属性:stdClass::$channels in Laravel Lumen,php,laravel,lumen,pusher,Php,Laravel,Lumen,Pusher,我正在用Lumen和Vue.JS制作POC。现在,它只需要从Lumen后端向Vue.JS前端发送一条“hello world”消息(这可以正常工作)。我制作了一个事件,在加载页面时触发如下: public function sendMessage(Request $request) { event(new MessageEvent('hello world')); } { ... "require": { ... &q

我正在用Lumen和Vue.JS制作POC。现在,它只需要从Lumen后端向Vue.JS前端发送一条“hello world”消息(这可以正常工作)。我制作了一个事件,在加载页面时触发如下:

public function sendMessage(Request $request)
{
    event(new MessageEvent('hello world'));
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "5.0"
        ...
    },
    ...
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "^5.0"
        ...
    },
    ...
}
MessageEvent如下所示(从Pusher getting started help获得):

这部分工作正常,因为我在Vue.JS应用程序中收到了:

Pusher :  : ["Event recd",{"event":"my-event","channel":"my-channel","data":{"message":"hello world"}}]
现在,当我检查队列日志时出现了问题。使用
php artisan队列:listen
触发,我看到以下内容:

[2021-03-14 11:57:03][Bh7373O9EETAZc39M2RCSPmUTjwSbSmL] Processing: App\Events\MessageEvent
[2021-03-14 11:57:04][Bh7373O9EETAZc39M2RCSPmUTjwSbSmL] Failed:     App\Events\MessageEvent
[2021-03-14 11:43:12] local.ERROR: Undefined property: stdClass::$channels {"exception":"[object] (ErrorException(code: 0): Undefined property: stdClass::$channels at /var/www/vendor/pusher/pusher-php-server/src/Pusher.php:538)
[2021-03-14 11:57:04] local.INFO: array (
  'body' => '{}',
  'status' => 200,
)  
当我检查流明日志文件时,它显示以下内容:

[2021-03-14 11:57:03][Bh7373O9EETAZc39M2RCSPmUTjwSbSmL] Processing: App\Events\MessageEvent
[2021-03-14 11:57:04][Bh7373O9EETAZc39M2RCSPmUTjwSbSmL] Failed:     App\Events\MessageEvent
[2021-03-14 11:43:12] local.ERROR: Undefined property: stdClass::$channels {"exception":"[object] (ErrorException(code: 0): Undefined property: stdClass::$channels at /var/www/vendor/pusher/pusher-php-server/src/Pusher.php:538)
[2021-03-14 11:57:04] local.INFO: array (
  'body' => '{}',
  'status' => 200,
)  
所以我继续检查Pusher.php文件:

536:         $result = json_decode($response['body']);
537:         
538:         if ($result->channels) {
539:             $result->channels = get_object_vars($result->channels);
540:         }
我决定检查
$response
是什么,它给出了以下内容:

[2021-03-14 11:57:03][Bh7373O9EETAZc39M2RCSPmUTjwSbSmL] Processing: App\Events\MessageEvent
[2021-03-14 11:57:04][Bh7373O9EETAZc39M2RCSPmUTjwSbSmL] Failed:     App\Events\MessageEvent
[2021-03-14 11:43:12] local.ERROR: Undefined property: stdClass::$channels {"exception":"[object] (ErrorException(code: 0): Undefined property: stdClass::$channels at /var/www/vendor/pusher/pusher-php-server/src/Pusher.php:538)
[2021-03-14 11:57:04] local.INFO: array (
  'body' => '{}',
  'status' => 200,
)  
当然,如果
response[“body”][“channels”]
不存在,它就无法访问
$result->channels

当我去检查Pusher API参考时,它会说:

这意味着主体确实应该包含一个JSON响应。但当我进一步滚动时,我看到:

这意味着您不必设置info参数,因为它是可选的和实验性的

[EXPERIMENTAL] If the info parameter is sent, then it returns a hash of unique channels that were triggered to. The hash maps from channel name to a hash of attributes for that channel (may be empty).
它对info参数集的预期响应如下:

{
  "channels": {
    "presence-foobar": {
      "user_count": 42,
      "subscription_count": 51
    },
    "presence-another": {
      "user_count": 123,
      "subscription_count": 140
    },
    "another": {
      "subscription_count": 13
    }
  }
}
哪个是请求的
频道
对象

我的问题是,我是错过了什么,还是这是Pusher的错误?我在这件事上真的很生气,所以我希望有人能帮我


Pusher-API参考:

修复composer.json

我在PHP软件包上创建了一个问题:

诚然,此版本已损坏,但修复程序应位于
composer.json
文件中。我的是这样的:

public function sendMessage(Request $request)
{
    event(new MessageEvent('hello world'));
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "5.0"
        ...
    },
    ...
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "^5.0"
        ...
    },
    ...
}
这意味着我明确地说它应该使用版本
5.0
。但现在我不会得到版本
5.2
,这意味着我不会得到补丁。据在Github上回答我问题的人说,我应该更改我的
composer.json
,并在版本号前面添加一个
^
,这样它就可以获得该版本的补丁。所以应该这样改变:

public function sendMessage(Request $request)
{
    event(new MessageEvent('hello world'));
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "5.0"
        ...
    },
    ...
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "^5.0"
        ...
    },
    ...
}
之后不要忘记运行
composer update

根据Github上的Graham Campbell:

任何将
5.0
放入其
composer.json
文件的人都犯了错误,因为composer将其解析为版本
5.0.0
,而不是版本约束
^5.0

Fix pusher.php(不推荐)

另一种解决方法是直接编辑
/vendor/pusher/pusher-php-server/src/pusher.php
。虽然不推荐,但它确实有效

536:         $result = json_decode($response['body']);
537:         
538:         if ($result->channels) {
539:             $result->channels = get_object_vars($result->channels);
540:         }
这不起作用,因为
结果
对象中不存在
通道。它应该首先检查通道对象是否存在。您可以将上述代码更改为:

536:         $result = json_decode($response['body']);
537:         
538:         if (property_exists($result, 'channels')) {
539:             $result->channels = get_object_vars($result->channels);
540:         }

修复composer.json

我在PHP软件包上创建了一个问题:

诚然,此版本已损坏,但修复程序应位于
composer.json
文件中。我的是这样的:

public function sendMessage(Request $request)
{
    event(new MessageEvent('hello world'));
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "5.0"
        ...
    },
    ...
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "^5.0"
        ...
    },
    ...
}
这意味着我明确地说它应该使用版本
5.0
。但现在我不会得到版本
5.2
,这意味着我不会得到补丁。据在Github上回答我问题的人说,我应该更改我的
composer.json
,并在版本号前面添加一个
^
,这样它就可以获得该版本的补丁。所以应该这样改变:

public function sendMessage(Request $request)
{
    event(new MessageEvent('hello world'));
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "5.0"
        ...
    },
    ...
}
{
    ...
    "require": {
        ...
        "pusher/pusher-php-server": "^5.0"
        ...
    },
    ...
}
之后不要忘记运行
composer update

根据Github上的Graham Campbell:

任何将
5.0
放入其
composer.json
文件的人都犯了错误,因为composer将其解析为版本
5.0.0
,而不是版本约束
^5.0

Fix pusher.php(不推荐)

另一种解决方法是直接编辑
/vendor/pusher/pusher-php-server/src/pusher.php
。虽然不推荐,但它确实有效

536:         $result = json_decode($response['body']);
537:         
538:         if ($result->channels) {
539:             $result->channels = get_object_vars($result->channels);
540:         }
这不起作用,因为
结果
对象中不存在
通道。它应该首先检查通道对象是否存在。您可以将上述代码更改为:

536:         $result = json_decode($response['body']);
537:         
538:         if (property_exists($result, 'channels')) {
539:             $result->channels = get_object_vars($result->channels);
540:         }