Skip to content

Commit

Permalink
php , very .....
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu committed Jan 11, 2022
1 parent c8dd9d6 commit 5c7e46d
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 1 deletion.
54 changes: 54 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/Mysqli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;

class Mysqli extends \mysqli
{
public function prepare ($query)
{
$plugin = new MysqliPreparePlugin("Mysqli::prepare",$this,$query);
try{
$plugin->onBefore();
$ret = parent::prepare($query);
$plugin->onEnd($ret);
return $ret;

}catch (\Exception $e)
{
$plugin->onException($e);
}
}

public function query ($query, $resultmode = NULL)
{
$plugin = new MysqliQueryPlugin("Mysqli::query",$this,$query, $resultmode);
try{
$plugin->onBefore();
$ret = parent::query($query,$resultmode);
$plugin->onEnd($ret);
return $ret;

}catch (\Exception $e)
{
$plugin->onException($e);
}
}
}

function mysqli_init() {
return new Mysqli();
}
37 changes: 37 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/MysqliPreparePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;


use Pinpoint\Plugins\Common\PinTrace;

class MysqliPreparePlugin extends PinTrace
{
function onBefore()
{
$myqli = $this->who;
pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL);
pinpoint_add_clue(PP_SQL_FORMAT, $this->args[0]);
pinpoint_add_clue(PP_DESTINATION,$myqli->host_info);
}

function onEnd(&$ret)
{
$origin = $ret;
$ret = new ProfilerMysqli_Stmt($origin);
}
}
37 changes: 37 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/MysqliQueryPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;


use Pinpoint\Plugins\Common\PinTrace;

class MysqliQueryPlugin extends PinTrace
{

function onBefore()
{
$myqli = $this->who;
pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL);
pinpoint_add_clue(PP_SQL_FORMAT,$this->args[0]);
pinpoint_add_clue(PP_DESTINATION,$myqli->host_info);
}

function onEnd(&$ret)
{

}
}
32 changes: 32 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/ProfilerMysqliResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;

class ProfilerMysqliResult
{
protected $_instance;
public function __construct(&$instance)
{
$this->_instance = &$instance;
}

public function __call($name, $arguments)
{
return call_user_func_array([&$this->_instance,$name],$arguments);
}

}
118 changes: 118 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/ProfilerMysqli_Stmt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/*
* User: eeliu
* Date: 11/5/20
* Time: 5:32 PM
* changes: 2022-1-11: php8.1, the only way is extends all function
*/

namespace Pinpoint\Plugins\Sys\mysqli7;


class ProfilerMysqli_Stmt extends \mysqli_stmt
{
protected $_instance;
public function __construct(&$instance)
{
$this->_instance = &$instance;
}

public function bind_result (&...$vars): bool
{
return $this->_instance->bind_result(...$vars);
}

public function execute(?array $params = null):bool
{
$plugin = new StmtExecutePlugin("Stmt::execute",$this);
try{
$plugin->onBefore();
$ret = call_user_func([$this->_instance,'execute']);
$plugin->onEnd($ret);
return $ret;

}catch (\Exception $e)
{
$plugin->onException($e);
}
}

public function attr_get( $attribute): int
{
return call_user_func([$this->_instance,'attr_get'],$attribute);
}

public function attr_set( $attribute, $value): bool
{
return call_user_func([$this->_instance,'attr_set'],$attribute,$value);
}

public function bind_param( $types, &...$vars): bool
{
return $this->_instance->bind_param($types,$vars);
}

public function close(): bool
{
return $this->_instance->close();
}
public function data_seek($offset): void
{
$this->_instance->data_seek($offset);
}

public function fetch(): ?bool
{
return $this->_instance->fetch();
}
public function free_result(): void
{
$this->_instance->free_result();
}

public function get_result(): \mysqli_result
{
return $this->_instance->get_result();
}

public function get_warnings(): \mysqli_warning
{
return $this->_instance->get_warnings();
}

public function more_results(): bool
{
return $this->_instance->more_results();
}
public function next_result(): bool
{
return $this->_instance->next_result();
}
public function num_rows(): int
{
return $this->_instance->num_rows();
}
public function prepare($query): bool
{
return $this->_instance->prepare($query);
}
public function reset(): bool
{
return $this->_instance->reset();
}
public function result_metadata(): \mysqli_result
{
return $this->_instance->result_metadata();
}

public function send_long_data( $param_num, $data): bool
{
return $this->_instance->send_long_data($param_num,$data);
}

public function store_result(): bool
{
return $this->_instance->store_result();
}

}
30 changes: 30 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/StmtExecutePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* User: eeliu
* Date: 11/5/20
* Time: 5:39 PM
*/

namespace Pinpoint\Plugins\Sys\mysqli7;


use Pinpoint\Plugins\Common\PinTrace;

/**
* Class StmtExecutePlugin
* record the function execute env
* @package Plugins\Sys\mysqli
*/
class StmtExecutePlugin extends PinTrace
{

function onBefore()
{
// TODO: Implement onBefore() method.
}

function onEnd(&$ret)
{
// TODO: Implement onEnd() method.
}
}
8 changes: 7 additions & 1 deletion lib/Pinpoint/Plugins/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@

if (function_exists('mysqli_connect'))
{
require_once __DIR__."/Sys/mysqli/Mysqli.php";
if(version_compare(phpversion(), '8.0.0', '<')){
require_once __DIR__."/Sys/mysqli7/Mysqli.php";
}elseif(version_compare(phpversion(), '8.0.0', '>=')){
require_once __DIR__."/Sys/mysqli/Mysqli.php";
}elseif(version_compare(phpversion(), '7.0.0', '<')){
throw new \Exception("not support php5+");
}
}

0 comments on commit 5c7e46d

Please sign in to comment.