Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. function request($link, $args)
  4. {
  5. $curl = curl_init();
  6.  
  7. curl_setopt_array($curl, [
  8.     CURLOPT_RETURNTRANSFER => true,
  9.     CURLOPT_POST           => true,
  10.     CURLOPT_FORBID_REUSE   => true,
  11.     CURLOPT_HEADER         => false,
  12.     CURLOPT_TIMEOUT        => 120,
  13.     CURLOPT_CONNECTTIMEOUT => 2,
  14.     CURLOPT_HTTPHEADER     => ["Connection: Keep-Alive", "Keep-Alive: 120"],
  15. ]);
  16.  
  17. curl_setopt_array($curl, [
  18.     CURLOPT_URL        => $link,
  19.     CURLOPT_POSTFIELDS => $args,
  20. ]);
  21.  
  22. $resultCurl = curl_exec($curl);
  23.  
  24. if($resultCurl === false)
  25. {
  26.     $arr = [
  27.         "ok"          => false,
  28.         "error_code"  => curl_errno($curl),
  29.         "description" => curl_error($curl),
  30.         "curl_error"  => true
  31.     ];
  32.  
  33.     $resultCurl = json_encode($arr);
  34. }
  35.  
  36.  
  37. $resultJson = json_decode($resultCurl);
  38.  
  39. if($resultJson === null)
  40. {
  41.     $arr = [
  42.         "ok"          => false,
  43.         "error_code"  => json_last_error(),
  44.         "description" => json_last_error_msg(),
  45.         "json_error"  => true
  46.     ];
  47.    
  48.     $resultJson = json_decode(json_encode($arr));
  49. }
  50.  
  51. return $resultJson;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement