Preparation

  • shadowsocks-libev
  • Laravel project
  • Guzzle

I will publish another blog post about shadowsocks-libev, stay tuned.

Laravel

Laravel 7.*

If you are using Laravel 7.* version, Guzzle is already encapsulated internally, and you can implement it as follows:

use Illuminate\Support\Facades\Http;

$response = Http::withOptions([
    'proxy' => 'socks5h://127.0.0.1:1080',
    'timeout' => 30
])->get('ip.sb');

return $response->body();

Use the withOptions method to set the request proxy, but pay attention to the proxy protocol. The difference between socks5 and socks5h is that socks5 will use local DNS resolution to get the domain name’s IP, which will result in getting the wrong server IP, so it is recommended to use socks5h.

Laravel Versions Before 7

composer require guzzlehttp/guzzle
use GuzzleHttp\Client;

$client = new Client();
$response = $client->get('ip.sb', [
    'proxy' => 'socks5h://127.0.0.1:1080',
    'timeout' => 30
]);

return $response->getBody()->getContents();

If everything goes well, the content in the response will be the IP of your Socks5 public node.

I hope this is helpful, Happy hacking…