#php #curl #tcpdump
Вопрос:
Я понятия не имею, почему это произошло. Я создал один запрос curl post для одной конечной точки и попытался записать журнал curl в таблицу mysql. В таблице mysql он сам записывает данные одной строки, из которых я получаю доступ к этому php-файлу.
Но если я проверю журнал tcpdump, он сделал двойные запросы на публикацию, которые всегда отображаются как двойной запрос в журнале tcpfump. Ниже приведен мой запрос на завиток:
lt;?php class DBCurl { ............... protected $pdo; protected $table; public function __construct(string $driver, string $database, string $host, string $user, string $password, string $table) { $this-gt;pdo = new PDO("$driver:dbname=$database;host=$host", $user, $password); $this-gt;table = $table; } public function insert(string $url, string $method, array $header, $body) : bool { $statement = $this-gt;pdo-gt;prepare(" INSERT INTO `$this-gt;table` (`url`, `method`, `request_header`, `request_body`) VALUES (:url, :method, :request_header, :request_body); "); $statement-gt;bindValue(':url', $url); $statement-gt;bindValue(':method', $method); $statement-gt;bindValue(':request_header', json_encode($header, JSON_UNESCAPED_SLASHES)); // $statement-gt;bindValue(':request_body', json_encode($body, JSON_UNESCAPED_SLASHES)); $statement-gt;bindValue(':request_body', $body); return $statement-gt;execute(); } protected function update(int $id, int $status, string $header, string $body) : bool { $statement = $this-gt;pdo-gt;prepare(" UPDATE `$this-gt;table` SET status=:status, response_header=:header, response_body=:body WHERE id=:id; "); $statement-gt;bindValue(':status', $status); $statement-gt;bindValue(':header', $header); $statement-gt;bindValue(':body', $body); $statement-gt;bindValue(':id', $id); return $statement-gt;execute(); } public function curl ($curl, string $response) { // EXECUTE: //$response = curl_exec($curl); $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if($httpcode) { $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); } else { ...... } $this-gt;update($this-gt;pdo-gt;lastInsertId(), $httpcode, $header, $body); } } $body = file_get_contents('php://input'); $dss_data = array( ...................... ); } $dss = curl_init(); curl_setopt($dss, CURLOPT_URL, $url); curl_setopt($dss, CURLOPT_RETURNTRANSFER, 1); curl_setopt($dss, CURLOPT_POST, 1); curl_setopt($dss, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($dss, CURLOPT_FOLLOWLOCATION, true); curl_setopt($dss, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($dss, CURLOPT_POSTFIELDS, json_encode($dss_data)); curl_setopt($dss, CURLOPT_HEADER, 1); $headers = array(); $headers[] = 'Authorization: 1234566'; $headers[] = 'Content-Type: application/json'; curl_setopt($dss, CURLOPT_HTTPHEADER, $headers); $dbCurl-gt;insert($url, 'POST', $headers, json_encode($dss_data)); ...................
Кто-нибудь может помочь найти его, почему? спасибо за любые предложения и подсказки