PHP Curl qua IPv6

Chào mọi người, em đang cần curl đến api của facebook, sử dụng php. Mọi khi em dùng proxy ipv4 chạy bình thường, nay em mua proxy v6 thì không chạy được, em có tìm qua mấy bài trên mạng làm theo nhưng cũng ko dc. Liệu có liên quan gì đến server không nhỉ ( trước dùng ipv4 e đã mở cho phép all port bằng iptables )

  • Code curl ipv4 (chạy dc)

          <?php
      function get($url)
      {
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
          curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Win) AppleWebKit/1000.0 (KHTML, like Gecko) Chrome/65.663 Safari/1000.01');
          curl_setopt($ch, CURLOPT_PROXY, '45.32.117.124');
          curl_setopt($ch, CURLOPT_PROXYPORT, '47876');
          curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'SCFCFm:LSdWk1');
          curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
          $result = curl_exec($ch);
          if(curl_errno($ch))
              die(curl_error($ch));
    
          var_dump(curl_getinfo($ch));
          curl_close($ch);
          return $result;
      }
    
      echo get('https://graph.facebook.com/'); // show result
    
  • Code curl ipv6 (ko hoạt động)

          <?php
      function get($url)
      {
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
          curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Win) AppleWebKit/1000.0 (KHTML, like Gecko) Chrome/65.663 Safari/1000.01');
          curl_setopt($ch, CURLOPT_PROXY, '[2001:19f0:4401:233:c127:605a:4cc8:7c26]');
          curl_setopt($ch, CURLOPT_PROXYPORT, '47876');
          curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'SCFCFm:LSdWk1');
          curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
          
          $result = curl_exec($ch);
          if(curl_errno($ch))
              die(curl_error($ch));
    
          var_dump(curl_getinfo($ch));
          curl_close($ch);
          return $result;
      }
    
      echo get('https://graph.facebook.com/');
    

Proxy Info:

image

hix hong co ai help dc ruii

Hi there,
Cậu gặp lỗi gì nhỉ Hoàng? Như mô tả, cậu chỉ đề cập là code không chạy được, nên bọn tớ cũng không hiểu được chuyện gì đã xảy ra :smiley:

6 Likes

Mã của bạn chạy tốt nên không có gì phải phàn nàn, nó còn tiết kiệm cho mình một vài phút viết code.

5 Likes

ipv6 khi curl nó báo như thế này anh ak.

Failed to connect to 2001:19f0:4401:233:c127:605a:4cc8:7c26: Network is unreachable

anh chạy trên server , os nào vậy anh. em cài vpssim: nginx+php-fpm+mariadb , os centos 6 64bit . em mở cho phép curl với proxy all port nhưng ipv6 thì nó báo lỗi

Failed to connect to 2001:19f0:4401:233:c127:605a:4cc8:7c26: Network is unreachable

nếu anh chạy được thì lỗi là do bên server chứ ko phải do code rồi, anh có biết nguyên nhân là gì ko ak ?

Sorry, có vẻ như ít thông tin quá, nên tớ không có ý tưởng gì giúp cậu được.
Cậu thử tham khảo câu trả lời này xem, ở đó có đưa ra 1 giả thiết cũng hợp lý:

5 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?