Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function request($link, $args)
- {
- $curl = curl_init();
- curl_setopt_array($curl, [
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_FORBID_REUSE => true,
- CURLOPT_HEADER => false,
- CURLOPT_TIMEOUT => 120,
- CURLOPT_CONNECTTIMEOUT => 2,
- CURLOPT_HTTPHEADER => ["Connection: Keep-Alive", "Keep-Alive: 120"],
- ]);
- curl_setopt_array($curl, [
- CURLOPT_URL => $link,
- CURLOPT_POSTFIELDS => $args,
- ]);
- $resultCurl = curl_exec($curl);
- if($resultCurl === false)
- {
- $arr = [
- "ok" => false,
- "error_code" => curl_errno($curl),
- "description" => curl_error($curl),
- "curl_error" => true
- ];
- $resultCurl = json_encode($arr);
- }
- $resultJson = json_decode($resultCurl);
- if($resultJson === null)
- {
- $arr = [
- "ok" => false,
- "error_code" => json_last_error(),
- "description" => json_last_error_msg(),
- "json_error" => true
- ];
- $resultJson = json_decode(json_encode($arr));
- }
- return $resultJson;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement