Giter Site home page Giter Site logo

phpcent's People

Contributors

aleksraiden avatar babl86 avatar beporter avatar darkkin avatar fzambia avatar juliustm avatar jumper572 avatar khvalov avatar sl4mmer avatar stevetherrien avatar tomchanskiy avatar vovan-ve avatar xaockd avatar yagobski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpcent's Issues

Does generatePrivateChannelToken need a way to set JWT 'sub' claim?

I'm upgrading my application to Centrifugo 4, and I'm getting a Connection Closed: 3500 invalid token error when I try to create a new subscription to a channel using a JWT created by generatePrivateChannelToken().

The server logs the following:

[INF] token user mismatch channel=$widget:206766-227029_52a5 client=[uuid] tokenUser= user=5555

where user=5555 came from the connection token's sub claim.

If I set "skip_user_check_in_subscription_token": true in the server config (as described in the v4 migration steps), then it succeeds:

[DBG] client subscribed to channel channel=$widget:206766-227029_52a5 client=[uuid] user=5555

This migration config option will eventually go away, and I don't want to rely on it.


I noticed generatePrivateChannelToken() lacks a way of setting a user ID into the JWT's sub claim (like is done in the generateConnectionToken() function right above it). If I modify it and inject my user's ID directly into the sub claim:

$payload['sub'] = '5555';

Then everything works without having to set the skip_user_check_in_subscription_token config option:

[DBG] client subscribed to channel channel=$widget:206766-227029_52a5 client=[uuid] user=5555

Am I missing something, or does generatePrivateChannelToken need a way to set the sub claim when subscribing to private channels?

Адаптация к новой версии центрифуги

Вот то, что изменилось:

github.com/centrifugal/cent/compare/centrifuge-0.8.0

А если словами, то:

— sha256 алгоритм вместо md5 для всех hmac-ов
— вместо project_id теперь project_key
— необязательно указывать /api в адресе подключения — если этого суффикса нет — то клиент автоматически его сам добавляет — это решает некоторые проблемы когда люди указывают в адресе при инициализации не «http://centrifuge.example.com/api», а просто «http://centrifuge.example.com»

json_decode error: Syntax error

I use lumen framework to install this package with 5.1.0 version.
lumen framework is 10.0.
when I try run this code on my local.
$client = new \phpcent\Client(env('CENTRIFUGO_BROADCAST_URL'), env('CENTRIFUGO_API_KEY'), env('CENTRIFUGO_HMAC_SECRET'));
$client->publish("channel-xxxxxx", ["message" => "Hello World"]);
it throw error
[2024-05-07 05:26:47] local.ERROR: json_decode error: Syntax error {"exception":"[object] (Exception(code: 0): json_decode error: Syntax error at /Users/a10116679/Desktop/project/lumenProject/vendor/centrifugal/phpcent/src/Client.php:389) [stacktrace] #0 /Users/a10116679/Desktop/project/lumenProject/vendor/centrifugal/phpcent/src/Client.php(144): phpcent\\Client->send('publish', Array) #1 /Users/a10116679/Desktop/project/lumenProject/app/Http/Controllers/RetailerSmartCartController.php(41): phpcent\\Client->publish('cart_channel_na...', Array) #2 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/container/BoundMethod.php(36): App\\Http\\Controllers\\RetailerSmartCartController->adb(Object(App\\Http\\Requests\\Api\\AdbRequest)) #3 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}() #4 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure)) #5 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure)) #6 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/container/Container.php(662): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL) #7 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(391): Illuminate\\Container\\Container->call(Array, Array) #8 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(356): Laravel\\Lumen\\Application->callControllerCallable(Array, Array) #9 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(331): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\RetailerSmartCartController), 'adb', Array) #10 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(284): Laravel\\Lumen\\Application->callControllerAction(Array) #11 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(264): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array) #12 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(48): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request)) #13 /Users/a10116679/Desktop/project/lumenProject/vendor/stancl/tenancy/src/Middleware/IdentificationMiddleware.php(36): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Laravel\\Lumen\\Http\\Request)) #14 /Users/a10116679/Desktop/project/lumenProject/vendor/stancl/tenancy/src/Middleware/InitializeTenancyByRequestData.php(46): Stancl\\Tenancy\\Middleware\\IdentificationMiddleware->initializeTenancy(Object(Laravel\\Lumen\\Http\\Request), Object(Closure), '867b8fb34b15403...') #15 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/pipeline/Pipeline.php(183): Stancl\\Tenancy\\Middleware\\InitializeTenancyByRequestData->handle(Object(Laravel\\Lumen\\Http\\Request), Object(Closure)) #16 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Laravel\\Lumen\\Http\\Request)) #17 /Users/a10116679/Desktop/project/lumenProject/vendor/illuminate/pipeline/Pipeline.php(119): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Laravel\\Lumen\\Http\\Request)) #18 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(428): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #19 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(263): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure)) #20 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(171): Laravel\\Lumen\\Application->handleFoundRoute(Array) #21 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(431): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request)) #22 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(167): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure)) #23 /Users/a10116679/Desktop/project/lumenProject/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(112): Laravel\\Lumen\\Application->dispatch(NULL) #24 /Users/a10116679/Desktop/project/lumenProject/public/index.php(28): Laravel\\Lumen\\Application->run() #25 {main} "}

Migrate library for Centrifugo v2

Does someone interested in migrating this library to support Centrifugo v2? We need 2 things:

  • migrate code to work with v2 (I can help explaining differences between v1 and v2 API)
  • make automatic releases over travis CI – so creating tag in this lib resulted in automatic uploading of new release to convenient PHP registry

$safety as non static

If set this
$client->setSafety(false);
get error
Notice: Accessing static property phpcent\Client::$safety as non static in Client.php on line 39

Query result parsed without ASSOC option of json_decode?!

I was quite surprised when presence_stats returned me object instead of array, I looked into sources and found:

    private function send($method, $params = [])
    {
	    $response = \json_decode($this->request($method, $params));
	    if (JSON_ERROR_NONE !== json_last_error()) {
          throw new \Exception(
            'json_decode error: ' . json_last_error_msg()
          );
        }
        return $response;
    }

Im wondering who ever uses json_decode without assoc option, at least there must be an option for it, but not hardcoded implicit false.

Disable curl's IPv6 host name resolution

I'm running into a problem where my application logs this error with phpcent several times each day:

cURL error: Resolving timed out after 2512 milliseconds

I'm using an internal DNS server and the timeout is 2s. We're IPv4 internally and don't use/publish IPv6 records.

Forcing IPv4 resolution with curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); solves the problem, and haven't had a single error in over 20 days, but that capability isn't exposed.

Would it be possible to let this option be set?

Subject: Inquiry Regarding token_hmac_secret_key Usage for Subscription Token Generation

Hello,

I hope this message finds you well. I've been exploring your repository with great interest, particularly regarding its capabilities around message publishing and subscription token generation. While reviewing the code, I noticed that there seems to be no mention of token_hmac_secret_key, which, as I understand, is essential for generating JWT tokens for subscription purposes in certain contexts.

Could you kindly clarify whether the tool is designed solely for publishing messages, without the capacity to generate tokens for subscribing? If it indeed lacks this functionality, could you please advise on the recommended approach to implement token generation for subscriptions? Any guidance or suggestions you could provide would be immensely appreciated.

Thank you for your time and for the efforts you've put into developing this tool. I look forward to your response.

Best regards!

PHP 7.2 Compile Error

Hi, I got PHP Compile Error on PHP 7.2

'Default value for parameters with a class type hint can only be NULL' in /usr/local/www/h/vendor/sl4mmer/phpcent/Client.php:18

public function __construct(string $url, string $apikey = '', string $secret = '')

DEPRECATED hash_hmac() passing null to parameter

There is a deprecation warning for php 8.1 in vendor/centrifugal/phpcent/src/Client.php on line 403 in "centrifugal/phpcent": "^5.1" version when calling $client->generateConnectionToken($userId) function.

Raw php warning message:
DEPRECATED hash_hmac(): Passing null to parameter #3 ($key) of type string is deprecated in vendor/centrifugal/phpcent/src/Client.php on line 403.

Fatal error: Allowed memory size during the installation

php 7.4.9
composer 1.10.17
Debian 10
RAM 4G

did this
composer require centrifugal/phpcent:~3.0

and got this
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 528384 bytes) in phar:///home/admin/.composer/composer/src/Composer/DependencyResolver/Pool.php on line 214

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 528384 bytes) in phar:///home/admin/.composer/composer/src/Composer/DependencyResolver/Pool.php on line 214

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

I tried to do
COMPOSER_MEMORY_LIMIT=3G composer require centrifugal/phpcent
COMPOSER_MEMORY_LIMIT=-1 composer require centrifugal/phpcent
set memory_limit = 3G in php.ini
set memory_limit = -1 in php.ini

and got
mmap() failed: [12] Cannot allocate memory

108. not available

Hello

 require DRUPAL_ROOT . '/sites/all/libraries/centrifugo/vendor/autoload.php';

  $client = new \phpcent\Client('https://****:8000/api');
  $client->setApiKey('****');

$channel = 'core';
$data = [
    'action' => 'notification',
    'data' => [
      'type' => 'warning',
      'title' => ' title',
      'content' => 'content',
      'duration' => 10000,
    ],
  ];

  $client->publish($channel, $data);

works fine (only I do not like the delay of almost a second for the server response)

just after


print_r($client->history($channel));

print_r($client->presence($channel));

for both requests, server returns 108, not available

Add support for http-client

Hi, thanks for this package!

I would be great if you could add support for using psr/http-client instead of hardcoded curl calls for duing the http calls as that would make it a lot easier to write tests of code that depends on this phpcent.

Either that or at least making the request and send methods protected so that it is possible to extend them and provide our own implementation of the http handling.

Regards,
Tarjei

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.