Test.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Command;
  4. use Hyperf\Command\Command as HyperfCommand;
  5. use Hyperf\Command\Annotation\Command;
  6. use Psr\Container\ContainerInterface;
  7. use App\Amqp\Producer\MqProducer;
  8. use App\JsonRpc\ChatServiceInterface;
  9. use App\JsonRpc\UserServiceInterface;
  10. use App\Service\Message\ReceiveHandleService;
  11. use App\Service\RedisService;
  12. use Hyperf\Amqp\Producer;
  13. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  14. use Hyperf\Contract\OnCloseInterface;
  15. use Hyperf\Contract\OnMessageInterface;
  16. use Hyperf\Contract\OnOpenInterface;
  17. use Hyperf\Di\Annotation\Inject;
  18. use Hyperf\Engine\WebSocket\Response;
  19. use Phper666\JWTAuth\JWT;
  20. #[Command]
  21. class Test extends HyperfCommand
  22. {
  23. public function __construct(protected ContainerInterface $container)
  24. {
  25. parent::__construct('demo:command');
  26. }
  27. public function configure()
  28. {
  29. parent::configure();
  30. $this->setDescription('Hyperf Demo Command');
  31. }
  32. public function handle()
  33. {
  34. //记录执行时间
  35. $start = microtime(true);
  36. for ($i = 0; $i < 200000; $i++) {
  37. $chatdata['receiver_id'] = 1;
  38. $chatdata['user_id'] = $i;
  39. $chatdata['group_receiver_id'] = 0;
  40. $chatdata['is_read'] = 1;
  41. $chatdata['action'] = 'said';
  42. $message = new MqProducer($chatdata);
  43. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  44. $re = $producer->produce($message);
  45. }
  46. $this->info(microtime(true) - $start);
  47. $this->line('Hello Hyperf!', 'info');
  48. }
  49. }