Outofmemory error tring debug MessageComponentInterface method vars












5















In my laravel 5.7 app I use MessageComponentInterface for chat app with a class like



<?php

namespace AppClassesSocket;

use AppClassesSocketBaseBaseSocket;
use RatchetMessageComponentInterface;
use RatchetConnectionInterface;

class ChatSocket extends BaseSocket
{
protected $clients;

public function __construct()
{
$this->clients = new SplObjectStorage;
}

public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
echo '<pre>New Connection ::'.print_r($conn->resourceId,true).'</pre>';
}

public function onMessage(ConnectionInterface $from, $msg) {
$numRecv= count($this->clients)-1;
echo '<pre>onMessage $msg::' . print_r( $msg, true ) ;
// var_dump($from);
dump($from);
die("-1 XXZ000");
echo '<pre>onMessage $from::' . print_r( $from, true ) ;
...


The problem is that in onMessage event I want to this message write to db table, but I can not find where to get user_id of user
who sent this message?
I tried to debug outputing values to screen with



echo '<pre>onMessage $from::' . print_r( $from, true ) ;


But I got outof memmory error, but in /etc/php/7.2/cli/php.ini I modified options:



max_execution_time = 3330
max_input_time = 240
memory_limit = 4048M


and restarted my server, but anyway I got outof memory error



using these metods:



//        var_dump($from);
dump($from);


I got endless output in console and I could not catch anything...



How to debug these values ?



UPDATED # 2
I try example at
https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet
article, but when I tried to run it with method :



public function onMessage(ConnectionInterface $from, $msg) {
$from->session->start();
$idUser = $from->session->get(Auth::getName());


I got error :



Undefined property: RatchetServerIoConnection::$session


In the mentioned article there was a comment :




(you must decrypt cookie to get the session id in Laravel 5) :




I search for this I found this




In web request context cookies are usually automatically encrypted and
decrypted by the EncryptCookies middleware. So easiest option would
be just to enable this middleware (and it's enabled by default in
Laravel).




and in my app/Http/Kernel.php there is line with EncryptCookies



protected $middlewareGroups = [
'web' => [
AppHttpMiddlewareEncryptCookies::class,


but that is web application, but I run console app.
Can the reason of the error that I have to add EncryptCookies to some other group in app/Http/Kernel.php ?
Or why error ?



Also
In file:///etc/php/7.2/cli/php.ini
I modified



memory_limit = 8048M


and restarted apache



also I tried to check how many of memory in my script :



         echo '<pre>onMessage getNiceFileSize(memory_get_usage()) ::' . print_r( $this->getNiceFileSize(memory_get_usage()) , true ) ;
it shows :19241736 ~18 MiB


error message :



 Out of memory (allocated 1623195648) (tried to allocate 1600131072 bytes)


I tried to calculated and got values 1.51 GiB and 1.49 GiB...




  • 1) why memory_get_usage returns such small value 2) Why dumping gets
    1.5 GiB? That is a big value 3) Any ideas how to deal it? 4) Auth::id() returns nothing and as far I understand it would not help,
    as message can be sent by some other logged user, but not currently
    logged...


Thanks!










share|improve this question





























    5















    In my laravel 5.7 app I use MessageComponentInterface for chat app with a class like



    <?php

    namespace AppClassesSocket;

    use AppClassesSocketBaseBaseSocket;
    use RatchetMessageComponentInterface;
    use RatchetConnectionInterface;

    class ChatSocket extends BaseSocket
    {
    protected $clients;

    public function __construct()
    {
    $this->clients = new SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn) {
    $this->clients->attach($conn);
    echo '<pre>New Connection ::'.print_r($conn->resourceId,true).'</pre>';
    }

    public function onMessage(ConnectionInterface $from, $msg) {
    $numRecv= count($this->clients)-1;
    echo '<pre>onMessage $msg::' . print_r( $msg, true ) ;
    // var_dump($from);
    dump($from);
    die("-1 XXZ000");
    echo '<pre>onMessage $from::' . print_r( $from, true ) ;
    ...


    The problem is that in onMessage event I want to this message write to db table, but I can not find where to get user_id of user
    who sent this message?
    I tried to debug outputing values to screen with



    echo '<pre>onMessage $from::' . print_r( $from, true ) ;


    But I got outof memmory error, but in /etc/php/7.2/cli/php.ini I modified options:



    max_execution_time = 3330
    max_input_time = 240
    memory_limit = 4048M


    and restarted my server, but anyway I got outof memory error



    using these metods:



    //        var_dump($from);
    dump($from);


    I got endless output in console and I could not catch anything...



    How to debug these values ?



    UPDATED # 2
    I try example at
    https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet
    article, but when I tried to run it with method :



    public function onMessage(ConnectionInterface $from, $msg) {
    $from->session->start();
    $idUser = $from->session->get(Auth::getName());


    I got error :



    Undefined property: RatchetServerIoConnection::$session


    In the mentioned article there was a comment :




    (you must decrypt cookie to get the session id in Laravel 5) :




    I search for this I found this




    In web request context cookies are usually automatically encrypted and
    decrypted by the EncryptCookies middleware. So easiest option would
    be just to enable this middleware (and it's enabled by default in
    Laravel).




    and in my app/Http/Kernel.php there is line with EncryptCookies



    protected $middlewareGroups = [
    'web' => [
    AppHttpMiddlewareEncryptCookies::class,


    but that is web application, but I run console app.
    Can the reason of the error that I have to add EncryptCookies to some other group in app/Http/Kernel.php ?
    Or why error ?



    Also
    In file:///etc/php/7.2/cli/php.ini
    I modified



    memory_limit = 8048M


    and restarted apache



    also I tried to check how many of memory in my script :



             echo '<pre>onMessage getNiceFileSize(memory_get_usage()) ::' . print_r( $this->getNiceFileSize(memory_get_usage()) , true ) ;
    it shows :19241736 ~18 MiB


    error message :



     Out of memory (allocated 1623195648) (tried to allocate 1600131072 bytes)


    I tried to calculated and got values 1.51 GiB and 1.49 GiB...




    • 1) why memory_get_usage returns such small value 2) Why dumping gets
      1.5 GiB? That is a big value 3) Any ideas how to deal it? 4) Auth::id() returns nothing and as far I understand it would not help,
      as message can be sent by some other logged user, but not currently
      logged...


    Thanks!










    share|improve this question



























      5












      5








      5


      0






      In my laravel 5.7 app I use MessageComponentInterface for chat app with a class like



      <?php

      namespace AppClassesSocket;

      use AppClassesSocketBaseBaseSocket;
      use RatchetMessageComponentInterface;
      use RatchetConnectionInterface;

      class ChatSocket extends BaseSocket
      {
      protected $clients;

      public function __construct()
      {
      $this->clients = new SplObjectStorage;
      }

      public function onOpen(ConnectionInterface $conn) {
      $this->clients->attach($conn);
      echo '<pre>New Connection ::'.print_r($conn->resourceId,true).'</pre>';
      }

      public function onMessage(ConnectionInterface $from, $msg) {
      $numRecv= count($this->clients)-1;
      echo '<pre>onMessage $msg::' . print_r( $msg, true ) ;
      // var_dump($from);
      dump($from);
      die("-1 XXZ000");
      echo '<pre>onMessage $from::' . print_r( $from, true ) ;
      ...


      The problem is that in onMessage event I want to this message write to db table, but I can not find where to get user_id of user
      who sent this message?
      I tried to debug outputing values to screen with



      echo '<pre>onMessage $from::' . print_r( $from, true ) ;


      But I got outof memmory error, but in /etc/php/7.2/cli/php.ini I modified options:



      max_execution_time = 3330
      max_input_time = 240
      memory_limit = 4048M


      and restarted my server, but anyway I got outof memory error



      using these metods:



      //        var_dump($from);
      dump($from);


      I got endless output in console and I could not catch anything...



      How to debug these values ?



      UPDATED # 2
      I try example at
      https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet
      article, but when I tried to run it with method :



      public function onMessage(ConnectionInterface $from, $msg) {
      $from->session->start();
      $idUser = $from->session->get(Auth::getName());


      I got error :



      Undefined property: RatchetServerIoConnection::$session


      In the mentioned article there was a comment :




      (you must decrypt cookie to get the session id in Laravel 5) :




      I search for this I found this




      In web request context cookies are usually automatically encrypted and
      decrypted by the EncryptCookies middleware. So easiest option would
      be just to enable this middleware (and it's enabled by default in
      Laravel).




      and in my app/Http/Kernel.php there is line with EncryptCookies



      protected $middlewareGroups = [
      'web' => [
      AppHttpMiddlewareEncryptCookies::class,


      but that is web application, but I run console app.
      Can the reason of the error that I have to add EncryptCookies to some other group in app/Http/Kernel.php ?
      Or why error ?



      Also
      In file:///etc/php/7.2/cli/php.ini
      I modified



      memory_limit = 8048M


      and restarted apache



      also I tried to check how many of memory in my script :



               echo '<pre>onMessage getNiceFileSize(memory_get_usage()) ::' . print_r( $this->getNiceFileSize(memory_get_usage()) , true ) ;
      it shows :19241736 ~18 MiB


      error message :



       Out of memory (allocated 1623195648) (tried to allocate 1600131072 bytes)


      I tried to calculated and got values 1.51 GiB and 1.49 GiB...




      • 1) why memory_get_usage returns such small value 2) Why dumping gets
        1.5 GiB? That is a big value 3) Any ideas how to deal it? 4) Auth::id() returns nothing and as far I understand it would not help,
        as message can be sent by some other logged user, but not currently
        logged...


      Thanks!










      share|improve this question
















      In my laravel 5.7 app I use MessageComponentInterface for chat app with a class like



      <?php

      namespace AppClassesSocket;

      use AppClassesSocketBaseBaseSocket;
      use RatchetMessageComponentInterface;
      use RatchetConnectionInterface;

      class ChatSocket extends BaseSocket
      {
      protected $clients;

      public function __construct()
      {
      $this->clients = new SplObjectStorage;
      }

      public function onOpen(ConnectionInterface $conn) {
      $this->clients->attach($conn);
      echo '<pre>New Connection ::'.print_r($conn->resourceId,true).'</pre>';
      }

      public function onMessage(ConnectionInterface $from, $msg) {
      $numRecv= count($this->clients)-1;
      echo '<pre>onMessage $msg::' . print_r( $msg, true ) ;
      // var_dump($from);
      dump($from);
      die("-1 XXZ000");
      echo '<pre>onMessage $from::' . print_r( $from, true ) ;
      ...


      The problem is that in onMessage event I want to this message write to db table, but I can not find where to get user_id of user
      who sent this message?
      I tried to debug outputing values to screen with



      echo '<pre>onMessage $from::' . print_r( $from, true ) ;


      But I got outof memmory error, but in /etc/php/7.2/cli/php.ini I modified options:



      max_execution_time = 3330
      max_input_time = 240
      memory_limit = 4048M


      and restarted my server, but anyway I got outof memory error



      using these metods:



      //        var_dump($from);
      dump($from);


      I got endless output in console and I could not catch anything...



      How to debug these values ?



      UPDATED # 2
      I try example at
      https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet
      article, but when I tried to run it with method :



      public function onMessage(ConnectionInterface $from, $msg) {
      $from->session->start();
      $idUser = $from->session->get(Auth::getName());


      I got error :



      Undefined property: RatchetServerIoConnection::$session


      In the mentioned article there was a comment :




      (you must decrypt cookie to get the session id in Laravel 5) :




      I search for this I found this




      In web request context cookies are usually automatically encrypted and
      decrypted by the EncryptCookies middleware. So easiest option would
      be just to enable this middleware (and it's enabled by default in
      Laravel).




      and in my app/Http/Kernel.php there is line with EncryptCookies



      protected $middlewareGroups = [
      'web' => [
      AppHttpMiddlewareEncryptCookies::class,


      but that is web application, but I run console app.
      Can the reason of the error that I have to add EncryptCookies to some other group in app/Http/Kernel.php ?
      Or why error ?



      Also
      In file:///etc/php/7.2/cli/php.ini
      I modified



      memory_limit = 8048M


      and restarted apache



      also I tried to check how many of memory in my script :



               echo '<pre>onMessage getNiceFileSize(memory_get_usage()) ::' . print_r( $this->getNiceFileSize(memory_get_usage()) , true ) ;
      it shows :19241736 ~18 MiB


      error message :



       Out of memory (allocated 1623195648) (tried to allocate 1600131072 bytes)


      I tried to calculated and got values 1.51 GiB and 1.49 GiB...




      • 1) why memory_get_usage returns such small value 2) Why dumping gets
        1.5 GiB? That is a big value 3) Any ideas how to deal it? 4) Auth::id() returns nothing and as far I understand it would not help,
        as message can be sent by some other logged user, but not currently
        logged...


      Thanks!







      laravel-5 socket.io






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 11 '18 at 4:27

























      asked Nov 25 '18 at 12:08







      user2054381































          1 Answer
          1






          active

          oldest

          votes


















          0














          Did yo see this https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet article ?
          It has similar example :



          public function onMessage(ConnectionInterface $from, $msg) {
          // start the session when the user send a message
          // (refreshing it to be sure that we have access to the current state of the session)
          $from->session->start();
          // do what you wants with the session
          // for example you can test if the user is auth and get his id back like this:
          $idUser = $from->session->get(Auth::getName());
          if (!isset($idUser)) {
          echo "the user is not logged via an http session";
          } else {
          $currentUser = User::find($idUser);
          }
          // or you can save data to the session
          $from->session->put('foo', 'bar');
          // ...
          // and at the end. save the session state to the store
          $from->session->save();
          }





          share|improve this answer
























          • Please look at UPDATED # 2 or original topic

            – user2054381
            Dec 11 '18 at 4:28











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467276%2foutofmemory-error-tring-debug-messagecomponentinterface-method-vars%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown
























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Did yo see this https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet article ?
          It has similar example :



          public function onMessage(ConnectionInterface $from, $msg) {
          // start the session when the user send a message
          // (refreshing it to be sure that we have access to the current state of the session)
          $from->session->start();
          // do what you wants with the session
          // for example you can test if the user is auth and get his id back like this:
          $idUser = $from->session->get(Auth::getName());
          if (!isset($idUser)) {
          echo "the user is not logged via an http session";
          } else {
          $currentUser = User::find($idUser);
          }
          // or you can save data to the session
          $from->session->put('foo', 'bar');
          // ...
          // and at the end. save the session state to the store
          $from->session->save();
          }





          share|improve this answer
























          • Please look at UPDATED # 2 or original topic

            – user2054381
            Dec 11 '18 at 4:28
















          0














          Did yo see this https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet article ?
          It has similar example :



          public function onMessage(ConnectionInterface $from, $msg) {
          // start the session when the user send a message
          // (refreshing it to be sure that we have access to the current state of the session)
          $from->session->start();
          // do what you wants with the session
          // for example you can test if the user is auth and get his id back like this:
          $idUser = $from->session->get(Auth::getName());
          if (!isset($idUser)) {
          echo "the user is not logged via an http session";
          } else {
          $currentUser = User::find($idUser);
          }
          // or you can save data to the session
          $from->session->put('foo', 'bar');
          // ...
          // and at the end. save the session state to the store
          $from->session->save();
          }





          share|improve this answer
























          • Please look at UPDATED # 2 or original topic

            – user2054381
            Dec 11 '18 at 4:28














          0












          0








          0







          Did yo see this https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet article ?
          It has similar example :



          public function onMessage(ConnectionInterface $from, $msg) {
          // start the session when the user send a message
          // (refreshing it to be sure that we have access to the current state of the session)
          $from->session->start();
          // do what you wants with the session
          // for example you can test if the user is auth and get his id back like this:
          $idUser = $from->session->get(Auth::getName());
          if (!isset($idUser)) {
          echo "the user is not logged via an http session";
          } else {
          $currentUser = User::find($idUser);
          }
          // or you can save data to the session
          $from->session->put('foo', 'bar');
          // ...
          // and at the end. save the session state to the store
          $from->session->save();
          }





          share|improve this answer













          Did yo see this https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet article ?
          It has similar example :



          public function onMessage(ConnectionInterface $from, $msg) {
          // start the session when the user send a message
          // (refreshing it to be sure that we have access to the current state of the session)
          $from->session->start();
          // do what you wants with the session
          // for example you can test if the user is auth and get his id back like this:
          $idUser = $from->session->get(Auth::getName());
          if (!isset($idUser)) {
          echo "the user is not logged via an http session";
          } else {
          $currentUser = User::find($idUser);
          }
          // or you can save data to the session
          $from->session->put('foo', 'bar');
          // ...
          // and at the end. save the session state to the store
          $from->session->save();
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 30 '18 at 18:12









          mstdmstdmstdmstd

          237614




          237614













          • Please look at UPDATED # 2 or original topic

            – user2054381
            Dec 11 '18 at 4:28



















          • Please look at UPDATED # 2 or original topic

            – user2054381
            Dec 11 '18 at 4:28

















          Please look at UPDATED # 2 or original topic

          – user2054381
          Dec 11 '18 at 4:28





          Please look at UPDATED # 2 or original topic

          – user2054381
          Dec 11 '18 at 4:28


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467276%2foutofmemory-error-tring-debug-messagecomponentinterface-method-vars%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)