Last active
June 6, 2025 06:36
-
-
Save jyxjjj/de36b5fdc45ff3f738066d88288dedea to your computer and use it in GitHub Desktop.
PHP cURL Clients
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function GET($url, $user_agent = 'CURL', $proxy_type = CURLPROXY_SOCKS5_HOSTNAME, $proxy = null, $header = null, $timeout = 10) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); | |
$header != null && curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
$proxy != null && curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type); | |
$proxy != null && curl_setopt($ch, CURLOPT_PROXY, $proxy); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
$file_contents = curl_exec($ch); | |
curl_close($ch); | |
return $file_contents; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function POST($url, $post_data = null, $user_agent = 'CURL', $proxy_type = CURLPROXY_SOCKS5_HOSTNAME, $proxy = null, $header = null, $timeout = 10) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$post_data != null && curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); | |
$user_agent != null && curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); | |
$header != null && curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
$proxy != null && curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type); | |
$proxy != null && curl_setopt($ch, CURLOPT_PROXY, $proxy); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
$file_contents = curl_exec($ch); | |
curl_close($ch); | |
return $file_contents; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Common\Helpers; | |
use App\Common\UA; | |
use DESMG\RFC8942\RequestHeader; | |
use Illuminate\Http\Client\PendingRequest; | |
use Illuminate\Support\Facades\Http; | |
class RequestHelper | |
{ | |
/** | |
* @param int $connectTimeout | |
* @param int $timeout | |
* @param int $retry | |
* @param int $retryDelay | |
* @param array $options | |
* @return PendingRequest | |
*/ | |
public static function getInstance(int $connectTimeout = 5, int $timeout = 5, int $retry = 3, int $retryDelay = 1000, array $options = []): PendingRequest | |
{ | |
return Http | |
::withHeaders( | |
new RequestHeader( | |
UA::CLIENT_VERSION, | |
UA::LINUX_VERSION, | |
UA::FEDORA_VERSION, | |
UA::MIN_CHROME_VERSION | |
)->getCURLHeaders() | |
) | |
->withOptions([ | |
'force_ip_resolve' => 'v4', | |
]) | |
->withOptions($options) | |
->connectTimeout($connectTimeout) | |
->timeout($timeout) | |
->retry($retry, $retryDelay, throw: false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment