work 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env php
  2. <?php
  3. use think\App;
  4. use Workerman\Worker as WO;
  5. define('APP_PATH', __DIR__ . '/application/');
  6. bcscale(2);
  7. // 加载框架引导文件
  8. require __DIR__.'/thinkphp/base.php';
  9. App::initCommon();
  10. WO::$logFile=sprintf('%s/workerman.log',RUNTIME_PATH);
  11. WO::$pidFile=sprintf('%s/workerman.pid',RUNTIME_PATH);
  12. WO::$processTitle='beauti-no';
  13. abstract class Com{
  14. protected static function log($data){
  15. user_log('commands/'.class_basename(get_called_class()),$data);
  16. }
  17. protected static function logError(\Exception $exception){
  18. user_log('commands/'.class_basename(get_called_class()),[
  19. 'exception'=>$exception->getMessage(),
  20. 'file'=>$exception->getFile().' line:'.$exception->getLine(),
  21. 'trace'=>$exception->getTrace()
  22. ]);
  23. }
  24. protected static function newWorker(){
  25. $work=new WO();
  26. $work->name=class_basename(static::class);
  27. return $work;
  28. }
  29. }
  30. foreach (glob(__DIR__.'/commands/*.php') as $file){
  31. require $file;
  32. }
  33. WO::runAll();