1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * 异步任务执行类
- */
- class Jobs
- {
- /**
- * 执行任务统一入口
- * @param string $name 任务名
- * @param array $args 参数列表
- */
- public function exec($name, $args)
- {
- if (!method_exists($this, $name)) {
- debug_log("method {$name} is not exits!", 'DEBUG', 'jobs');
- return false;
- }
- return call_user_func_array([$this, $name], $args);
- }
- /**
- * 测试
- */
- protected function test()
- {
- $args = func_get_args();
- debug_log('test(' . implode(',', $args) . ');', 'DEBUG', 'jobs');
- }
- /**
- * 抓百度页面
- */
- protected function curl_get($url)
- {
- if (empty($url)) {
- return;
- }
- $get = [];
- $opt = [];
- $error = '';
- $errno = 0;
- $code = 0;
- $resp = curl_get($url, $get, $opt, $error, $errno, $code);
- if ($errno || $code != 200) {
- debug_log("curl_get({$url}) failed: #{$errno},{$error},http-status={$code}", 'ERROR', 'jobs');
- } else {
- debug_log("curl_get({$url}) => {$resp}", 'DEBUG', 'jobs');
- }
- }
- /**
- * 打印当前进程的id
- */
- protected function pid()
- {
- debug_log('Current process\'s id is: ' . getmypid(), 'DEBUG', 'jobs');
- }
- }
|