Code Monkey home page Code Monkey logo

aliyun-log-php-sdk's Introduction

Aliyun Log Service PHP SDK

API VERSION

0.6.4

SDK RELEASE TIME

2024-05-28

Introduction

Log Service SDK for PHP,used to set/get log data to Aliyun Log Service(www.aliyun.com/product/sls).

API Reference: 中文 ENGLISH

Summary

  1. Request-Request style Restful API interface
  2. Use Protocol buffer to send data
  3. Data can be compressed when sending to server
  4. Aliyun_Log_Exception will be thrown if any error happen
  5. Introduce simple logger for submit log easily with different levels
  6. Create local log cache to submit several logs in single http post.

Environment Requirement

  1. PHP 7.1.7 and later:Master Branch
  2. PHP 5.2+:Tree v1.0

aliyun-log-php-sdk's People

Contributors

crimson-gao avatar fnck avatar mayunlei avatar qiansheng91 avatar sandbeach avatar suntingtao007 avatar tangkai1719 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aliyun-log-php-sdk's Issues

PHP 时区被限定为东八区

PHP 的时区设置,在代码中被设置为了东八区,这个可不可以去掉,或者作为配置项,可以配置时区

sdk

SDK有说明文档吗?
topic以及source指什么?

php sdk会报错

报错内容如下:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: RequestCore::$HTTP/1.1 200 Server: nginx/1.8.0 Content-Type: application/json Content-Length: 46 Connection: close Date: Fri, 03 Mar 2017 09:19:14 GMT x-log-requestid: 58B93512F269FB2E33638216 {"count":1,"logstores":["pay-log"],"total":1}

Filename: Log/requestcore.class.php

Line Number: 796

问题出在Log/requestcore.class.php第796行,具体修改如下:

//原代码:
if ($curl_handle && $this->$response)
{
	return new $this->response_class($this->response_headers, $this->response_body, $this->response_code, $curl_handle);
}
//修改:
if ($curl_handle && $this->response)
{
	return new $this->response_class($this->response_headers, $this->response_body, $this->response_code, $curl_handle);
}

使用 count 会有 notice

使用 sample.php 中的 getLogs 方法,将其中的 query 的为 " query | timeslice 24h | count " 时会有 notice

PHP Notice: Undefined index: source in ******/aliyun-log-php-sdk/Aliyun/Log/Models/Response/GetLogsResponse.php on line 48

sample/sample.php 文件改造如下:

 58 function getLogs(Aliyun_Log_Client $client, $project, $logstore) {
 59     // $topic = 'TestTopic';
 60     $topic = '';
 61     $from = time()-86400;
 62     $to = time();
 63     $query = 'type:adc | timeslice 12h | count';
 64     // $query = '';
 65     $request = new Aliyun_Log_Models_GetLogsRequest($project, $logstore, $from, $to, $topic, $query, 100, 0, False);
 66
 67     try {
 68         $response = $client->getLogs($request);
 69         foreach($response -> getLogs() as $log)
 70         {
 71             print $log -> getTime()."\t";
 72             foreach($log -> getContents() as $key => $value){
 73                 print $key.":".$value."\t";
 74             }
 75             print "\n";
 76         }
 77
 78     } catch (Aliyun_Log_Exception $ex) {
 79         logVarDump($ex);
 80     } catch (Exception $ex) {
 81         logVarDump($ex);
 82     }
 83 }

Required fields are missing

PHP8.0
Macos
Laravel9.33
alibabacloud/aliyun-log-php-sdk:0.6.3

具体错误调用栈:
#0 /data/api/vendor/alibabacloud/aliyun-log-php-sdk/Aliyun/Log/sls.proto.php(191): Log_Content->write(Resource id #8)
#1 /data/api/vendor/alibabacloud/aliyun-log-php-sdk/Aliyun/Log/sls.proto.php(335): Log->write(Resource id #8)
#2 /data/api/vendor/alibabacloud/aliyun-log-php-sdk/Aliyun/Log/Util.php(62): LogGroup->write(Resource id #8)
#3 /data/api/vendor/alibabacloud/aliyun-log-php-sdk/Aliyun/Log/Client.php(258): Aliyun_Log_Util::toBytes(Object(LogGroup))
#4 /data/api/app/Lib/AliLog.php(69): Aliyun_Log_Client->putLogs(Object(Aliyun_Log_Models_PutLogsRequest))
#5 /data/api/app/Http/Controllers/Api/SentryController.php(59): App\Lib\AliLog->write('Uncaught Refere...')
#6 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\Api\SentryController->report(O ▶
#7 /data/api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction ▶
#8 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\ControllerDispatcher->dispatch(Objec ▶
#9 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\Routing\Route->runController()
#10 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(725): Illuminate\Routing\Route->run()
#11 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing{clo ▶
#12 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->I ▶
#13 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings-> ▶
#14 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(126): Illuminate\Pipeline\Pipeline->Il ▶
#15 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(102): Illuminate\Routing\Middleware\Th ▶
#16 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(54): Illuminate\Routing\Middleware\Thr ▶
#17 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\ThrottleRequests->ha ▶
#18 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\ ▶
#19 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#20 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(703): Illuminate\Routing\Router->runRouteWithinStack(Object ▶
#21 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(667): Illuminate\Routing\Router->runRoute(Object(Illuminate ▶
#22 /data/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(656): Illuminate\Routing\Router->dispatchToRoute(Object(Ill ▶
#23 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Routing\Router->dispatch(Object(Il ▶
#24 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foun ▶
#25 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipe ▶
#26 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Found ▶
#27 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ConvertEmpty ▶
#28 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipe ▶
#29 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Mid ▶
#30 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings- ▶
#31 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipel ▶
#32 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePost ▶
#33 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminat ▶
#34 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventReque ▶
#35 /data/api/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(62): Illuminate\Pipeline\Pipeline->Illuminate\P ▶
#36 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\HandleCors->handle(Obje ▶
#37 /data/api/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate ▶
#38 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle(Ob ▶
#39 /data/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\ ▶
#40 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then(Object(Clo ▶
#41 /data/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendReques ▶
#42 /data/api/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#43 {main}

CPU异常使用问题

通过排查发现这个方法会导致CPU偏高,如果fread调整为1M和10M估计有3-4倍的差异。但1M可能出现大日志写不全的问题。

File: aliyun-log-php-sdk/blob/master/Aliyun/Log/Util.php

    public static function toBytes($logGroup) {
        $mem = fopen("php://memory", "rwb");
        $logGroup->write($mem);
        rewind($mem);
        $bytes="";
      
        if(feof($mem)===false){
            $bytes = fread($mem, 10*1024*1024);
        }
        fclose($mem);
        return $bytes;

cURL Operation timed out

RequestCore_Exception: cURL resource: Resource id #129; cURL error: Operation timed out after 20001 milliseconds with 0 out of -1 bytes received (28)
curl超时怎么自定义设置?

进程卡死,目测是卡在curl

#0 0x00007fe0c1462e2d in poll () from /lib64/libc.so.6
#1 0x00007fe0c240f2b9 in Curl_poll () from /lib64/libcurl.so.4
#2 0x00007fe0c24081fd in curl_multi_wait () from /lib64/libcurl.so.4
#3 0x00007fe0c240132f in curl_easy_perform () from /lib64/libcurl.so.4
#4 0x000000000056bef9 in zif_curl_exec (execute_data=, return_value=0x7fe0bd614d20) at /data/download/php-7.1.6/ext/curl/interface.c:3032
#5 0x000000000080f2b6 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at /data/download/php-7.1.6/Zend/zend_vm_execute.h:675
#6 0x00000000007ff49b in execute_ex (ex=) at /data/download/php-7.1.6/Zend/zend_vm_execute.h:429
#7 0x00000000007ab361 in zend_call_function (fci=fci@entry=0x7ffe64ebb080, fci_cache=0x7ffe64ebafc0, fci_cache@entry=0x0) at /data/download/php-7.1.6/Zend/zend_execute_API.c:855

(gdb) zbacktrace
[0x7fe0bd614e50] curl_exec(resource(#-1117430832)) [internal function]
[0x7fe0bd614c60] RequestCore->send_request() /data/webroot/shuangshi/release/plugin/Aliyun/Log/requestcore.class.php:817
[0x7fe0bd614a30] Aliyun_Log_Client->getHttpResponse("GET", "http://shuangshi.cn-beijing.log.aliyuncs.com:80/logstores/doubleteacher_analytics_java/shards", NULL, array(8)[0x7fe0bd614ab0]) /data/webroot/shuangshi/release/plugin/Aliyun/Log/Client.php:141
[0x7fe0bd614720] Aliyun_Log_Client->sendRequest("GET", "http://shuangshi.cn-beijing.log.aliyuncs.com:80/logstores/doubleteacher_analytics_java/shards", NULL, array(8)[0x7fe0bd6147a0]) /data/webroot/shuangshi/release/plugin/Aliyun/Log/Client.php:156
[0x7fe0bd614290] Aliyun_Log_Client->send("GET", "shuangshi", NULL, "/logstores/doubleteacher_analytics_java/shards", array(0)[0x7fe0bd614320], array(8)[0x7fe0bd614330]) /data/webroot/shuangshi/release/plugin/Aliyun/Log/Client.php:219
[0x7fe0bd613ff0] Aliyun_Log_Client->listShards(object[0x7fe0bd614040]) /data/webroot/shuangshi/release/plugin/Aliyun/Log/Client.php:543
[0x7fe0bd613ac0] Interaction->checkAllProcess() /data/webroot/shuangshi/release/daemon/aliyunpulllog/src/core/pull/Interaction.php:142
[0x7fe0bd6135b0] LogMonitor->monitor(object[0x7fe0bd613600]) /data/webroot/shuangshi/release/daemon/aliyunpulllog/src/logmonitor.php:220

卡死了,

BUG Object of class CurlHandle could not be converted to string

Object of class CurlHandle could not be converted to string {"exception":"[object] (Error(code: 0): Object of class CurlHandle could not be converted to string at /var/www/html/vendor/alibabacloud/aliyun-log-php-sdk/Aliyun/Log/requestcore.class.php:835

[RequestError] Request is failed. Http code is 0.

PHP8 因为 is_resource 的返回值改变,抛出了异常

public function process_response 中的

if (is_resource($this->curl_handle)) {

改为

if (is_resource($curl_handle) || (is_object($curl_handle) && get_class($curl_handle) === 'CurlHandle')) {

通过composer引入后,类名重复

用composer autoload files来加载了,结果项目里有个Log类,和你们的Log类冲突了,报错Fatal error: Cannot declare class Log, because the name is already in use in E:\wwwroot\api-console\extra\aliyun-log\Aliyun\Log\sls.proto.php on line 129,这个有点致命了,因为你们的autoload方式所有类直接引入了全局名称空间,只要有任何一个地方和你们撞类名,你们这个SDK就不能用。

ERROR AGAIN

[cURL resource: Resource id #81; cURL error: Maximum (5) redirects followed (47)] Aliyun_Log_Exception in Client.php line 159

sls.proto.php->size方法

if (!is_null($this->value_))
{
if (is_array($this->value_))//这里需要增加数组的判断 不然下面的strlen报错
{
$this->value_ = Protobuf::toString('value_', $this->value_);
}
$l = strlen($this->value_);
$size += 1 + Protobuf::size_varint($l) + $l;
}

Log 冲突

Fatal error: Cannot declare class Log, because the name is already in use in /data/app/vendor/alibabacloud/aliyun-log-php-sdk/Aliyun/Log/sls.proto.php on line 129

本身你就是一个组件,你还不用命名空间
不用命名空间也行,你用长一点的命名呗,偏不!!!!!!

实测与 lumen 框架冲突
lumen ./bootstrap/app.php 里面
$app->withFacades(); 方法调用了 vendor/laravel/lumen-framework/src/Application.php
这里面定义了很多类的别名 ,导致 Log 冲突

解决方法 修改 ./bootstrap/app.php
别名指向空字符串

$app->withFacades(true, [
    \Illuminate\Support\Facades\Log::class => '',
]);

php cannot declare class protobufmessage, because the name is already in use

Aliyun/Log/Client.php 中的代码需要注释掉 如下
require_once realpath ( dirname ( FILE ) . '/../../Log_Autoload.php' );
require_once realpath ( dirname ( FILE ) . '/requestcore.class.php' );
require_once realpath ( dirname ( FILE ) . '/sls.proto.php' );
// require_once realpath ( dirname ( FILE ) . '/protocolbuffers.inc.php' );

使用时间作为offset是否有缺陷?

当拉取进度和服务器时间相同时,某条日志在时间1秒内。

如 xxx0.001秒内写入两条日志,第一条在a分区,第二条也在a分区。
拉取同分区日志时的时间为xxx0.331秒,这时第一条日志刚能拉取到,第二条还未写入,这时提示日志到底。

再次拉取时间为xxx0.631秒 还在一秒范围内,这时会返回第一条第二条日志。日志有重复。如果+1秒获取则会丢失第二条日志。

WTF ! PHP Notice happen on Util.php

Severity: Notice

Message: Undefined variable: out

Filename: Log/Util.php

Line Number: 20


Severity: Notice

Message: Undefined variable: stats

Filename: Log/Util.php

Line Number: 20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.