Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. require __DIR__ . '/vendor/autoload.php';
  2.  
  3. use React\MySQL\Factory;
  4. use React\MySQL\QueryResult;
  5.  
  6. use Clue\React\Block;
  7.  
  8. $loop = React\EventLoop\Factory::create();
  9. $factory = new Factory($loop);
  10.  
  11. $loop->addPeriodicTimer(3.0, function() use ($loop, $factory) {
  12.  
  13. echo "trying to run a query...\n";
  14.  
  15. $uri = DB_USER . ':' . rawurlencode(DB_PASS) . "@" . DB_HOST . "/" . DB_NAME;
  16. $connection = $factory->createLazyConnection($uri);
  17.  
  18. $promise = $connection->query('SELECT * FROM table ORDER BY ts desc limit 1');
  19.  
  20. try {
  21.  
  22. $ret = Block\await($promise, $loop);
  23. echo "done with " . count($ret->resultRows) . " rows\n";
  24. $connection->quit();
  25.  
  26. } catch (Exception $e) {
  27. // promise rejected with $exception
  28. echo 'ERROR: ' . $e->getMessage();
  29. }
  30.  
  31. });
  32.  
  33. $loop->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement