Ratchet Symfony 2 and "cache" data.

190 views
Skip to first unread message

David

unread,
Mar 7, 2013, 1:43:02 AM3/7/13
to ratch...@googlegroups.com
Hi.

Thanks to documentation,examples and mailing list I could install Ratchet with Symfony 2 using WampServer component.
However, I have a problem when trying to retrieve information from my database using Doctrine. The problem is that in the method onCall trying to retrieve the information, Doctrineme returns "cache" results.

This is basically what I try to do.

// In my database
#product

 id     |    name   |    description   |    price
--------+------------+------------------- +----------
1        |  cat food |     cat food       |  1.25

// Client
function callProcedure($product) {
sess.call("http://mysite:8080/update", $product).then(
     function (res) {
        // I hope receive the last price from a product
     },
     function (error, desc) {
        console.log("error: " + desc);
     }
  );
}

// Symfony WampServer
public function onCall(ConnectionInterface $conn, $id, $procURI, array $params)
{
      $repository = $this->container->get('doctrine')->getManager()
            ->getRepository('StoreProductBundle:Product');
        $product = $repository->findOneById($params[0]);   
       if($product)
       {
    $coon->event($id, array( ‘price’ => $product->getPrice() ));
       }
       else
       {
    $conn->callError($id, $topic, 'Product not found’');
       }
}

When I run the server and call the function callProcedure on mi JS, the server sent the price 1.25. But if I update the product price in another process, and call again callProcedure the server always send the original price (1.25) no matter how many times I call this function.
I need to stop and run again the server for see changes in the product price.

any ideas?

Cheers.

David

unread,
Mar 7, 2013, 8:36:56 PM3/7/13
to ratch...@googlegroups.com
I use a raw query and works fine.

cboden

unread,
Mar 9, 2013, 11:26:54 AM3/9/13
to ratch...@googlegroups.com
Hi David,

This sounds like Doctrine is caching its results in memory.  As Ratchet is a long-running application, unlike most PHP websites, this behaviour would usually be desired. I'm not an expert on Doctrine, but I believe you would have to explicitly clear its cache. 

Also, it's usually not a good idea to run sql queries in a Ratchet application.  As multiple clients are on a single event loop, a single blocking sql query would make all connected clients wait for that one call.

Cheers.

bosuy...@gmail.com

unread,
Nov 23, 2015, 12:54:38 PM11/23/15
to Ratchet
just clear your EntityManager(s) at the end of onCall method. Any way need to run something like this: $container->get('doctrine.orm.entity_manager')->clear();

четверг, 7 марта 2013 г., 8:43:02 UTC+2 пользователь David написал:
Reply all
Reply to author
Forward
0 new messages