IndexAction.class.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. class IndexAction extends Action {
  3. public function index( ){
  4. echo 'hello world';
  5. }
  6. public function create_route(){
  7. if( PHP_SAPI != 'cli' ){
  8. exit(PHP_SAPI);
  9. }
  10. echo '['.date('Y-m-d H:i:s').'] ———————————————————— starting create route ———————————————————— '.PHP_EOL;
  11. // 模拟添加数据,10万个标签,每个每秒产生1条数据
  12. $gps = M('gps_location_20190412','','mysql://dev:711e7D69f9d0c3f1@rm-bp13qpl023g02660t.mysql.rds.aliyuncs.com:3306/dev_fd_gps');
  13. $start_time = 1555050000; //2019-3-30 00:00:00
  14. while ( $start_time <= 1555050076) { //2019-3-30 23:59:59
  15. $deive_id = 100000000000001;
  16. for( $i=1; $i <= 100000; $i++ ){
  17. if( $i % 1200 == 1 ){
  18. $start_submit = microtime(true);
  19. $gps->startTrans();
  20. $data = array();
  21. }
  22. $data[] = array(
  23. 'DeviceId' => $deive_id + $i,
  24. 'DeviceTime' => $start_time,
  25. 'Longitude' => 120 + rand(200001,220562)/1000000,
  26. 'Latitude' => 30 + rand(260001,260818)/1000000,
  27. 'Speed' => rand(0, 40),
  28. 'Direction' => rand(1,8),
  29. 'Status' => rand(1,10),
  30. 'SatelliteCount' => rand(4,11),
  31. 'LBS' => 'abcdefgh'
  32. );
  33. if( $i % 1200 == 0 ){
  34. $gps->addAll($data);
  35. $gps->commit();
  36. $end_submit = microtime(true);
  37. var_dump('now ' . $i .' use ' . ($start_submit - $end_submit) .' memory_get_usage :' . memory_get_usage());
  38. }
  39. }
  40. usleep(1000);
  41. $start_time ++;
  42. }
  43. echo '['.date('Y-m-d H:i:s').'] ———————————————————— create route finished ———————————————————— '.PHP_EOL;
  44. }
  45. }