Automation/app/Libraries/MySocket/CloudflareSocket.php
2024-09-19 23:19:54 +09:00

39 lines
1.1 KiB
PHP

<?php
namespace App\Libraries\MySocket;
use App\Libraries\CommonLibrary;
use Cloudflare\API\Adapter\Guzzle;
use Cloudflare\API\Auth\APIKey;
class CloudflareSocket extends CommonLibrary
{
private static int $_request = 0;
private static int $_request_max = 100;
private static int $_request_timewait = 60;
private $_client = null;
public function __construct(string $email, string $api_key)
{
parent::__construct();
$this->_email = $email;
$this->_api_key = $api_key;
self::$_request_max = getenv("cfmgr.request.max");
}
final public function getClient(): Guzzle
{
if ($this->_client === null) {
$this->_client = new Guzzle(
$this->_client = new APIKey($this->_email, $this->_api_key)
);
}
if (self::$_request >= self::$_request_max) {
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
sleep(intval(getenv("cf.mgr.request.time.wait")));
self::$_request = 0;
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
}
self::$_request++;
return $this->_client;
}
}