Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Curl + Proxy = Wielki problem.
Forum PHP.pl > Forum > PHP
ones
Witam!
Normalnie używam curl_get do pobrania strony i poprzez explode itd pobieram interesujące mnie dane w pętli..
Tylko jest problem, jak chcę to zrobić poprzez proxy..
Próbowałem coś takiego:
  1. $url = "http://adrestrony.pl";
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL,$url);
  4. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
  5. curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
  6. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  8. curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
  9. curl_setopt ($ch, CURLOPT_HEADER, 1);
  10. curl_exec ($ch);
  11. $curl_scraped_page = curl_exec($ch);
  12. curl_close($ch);
  13. $zmiennadoexpldoe = $curl_scraped_page;


0 wyników, czasem błędy.. Czy ktoś może mi pomóc w tej kwestii ?
mat-bi
Zdecyduj się:
  1. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);

- wyłączasz proxy

  1. curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');

- podajesz adres proxy
...
ones
Ale jak daje tam 1 to jest to samo...
mat-bi
zapomniałem - curl_error() i curl_errno()
ones
Błędy:
Kod
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/oness/domains/my-mp.pl/public_html/includes/sources/mp3skull_local.php on line 13
HTTP/1.0 504 Gateway Time-out Server: squid/2.7.STABLE9 Date: Tue, 12 Jul 2011 11:32:52 GMT Content-Type: text/html Content-Length: 1237 X-Squid-Error: ERR_DNS_FAIL 0 X-Cache: MISS from easy-cdn-node Via: 1.0 easy-cdn-node:80 (squid/2.7.STABLE9) Connection: close
The requested URL could not be retrieved

While trying to retrieve the URL: http://mp3skull.com/search.php?q=shakira&submit=Search

The following error was encountered:

Unable to determine IP address from host name for mp3skull.com
The dnsserver returned:

No DNS records
This means that:

The cache was not able to resolve the hostname presented in the URL.
Check if the address is correct.
Your cache administrator is support@dilehost.com.
Generated Tue, 12 Jul 2011 11:32:52 GMT by easy-cdn-node (squid/2.7.STABLE9)
HTTP/1.0 504 Gateway Time-out Server: squid/2.7.STABLE9 Date: Tue, 12 Jul 2011 11:32:53 GMT Content-Type: text/html Content-Length: 1237 X-Squid-Error: ERR_DNS_FAIL 0 X-Cache: MISS from easy-cdn-node Via: 1.0 easy-cdn-node:80 (squid/2.7.STABLE9) Connection: close
The requested URL could not be retrieved

While trying to retrieve the URL: http://mp3skull.com/search.php?q=shakira&submit=Search

The following error was encountered:

Unable to determine IP address from host name for mp3skull.com
The dnsserver returned:

No DNS records
This means that:

The cache was not able to resolve the hostname presented in the URL.
Check if the address is correct.
Your cache administrator is support@dilehost.com.
Generated Tue, 12 Jul 2011 11:32:53 GMT by easy-cdn-node (squid/2.7.STABLE9)

Warning: curl_error(): 109 is not a valid cURL handle resource in /home/oness/domains/my-mp.pl/public_html/includes/sources/mp3skull_local.php on line 21


linia 13-sta:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Linia 21:
echo curl_error($ch);
To jak miałem CURLOPT_HTTPPROXYTUNNEL 0 A teraz jak mam ustawione na 1:


Kod
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/oness/domains/my-mp.pl/public_html/includes/sources/mp3skull_local.php on line 13
HTTP/1.0 400 Bad Request Server: squid/2.7.STABLE9 Date: Tue, 12 Jul 2011 11:34:59 GMT Content-Type: text/html Content-Length: 1281 X-Squid-Error: ERR_INVALID_REQ 0 X-Cache: MISS from easy-cdn-node Via: 1.0 easy-cdn-node:80 (squid/2.7.STABLE9) Connection: close HTTP/1.0 400 Bad Request Server: squid/2.7.STABLE9 Date: Tue, 12 Jul 2011 11:34:59 GMT Content-Type: text/html Content-Length: 1281 X-Squid-Error: ERR_INVALID_REQ 0 X-Cache: MISS from easy-cdn-node Via: 1.0 easy-cdn-node:80 (squid/2.7.STABLE9) Connection: close
Warning: curl_error(): 109 is not a valid cURL handle resource in /home/oness/domains/my-mp.pl/public_html/includes/sources/mp3skull_local.php on line 21
mat-bi
Gratuluję hostingu. Safe mode? Toz te g**** nie ma dawno nawet na darmowych...
ones
Wyłączyć save mode tak?

Wyłączone save mode i dalej to samo.

Ten błąd zniknął:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/oness/domains/my-mp.pl/public_html/includes/sources/mp3skull_local.php on line 13


Ale dalej nie działa, reszta nadal wyświetla się jak podałem..

Bitwy ciąg dalszy..
Pozmieniałem nieco kod..
Teraz wyskakuje mi:
Kod
Received HTTP code 400 from proxy after CONNECT


Kod:
  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_URL,$url);
  3. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  4. curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
  5. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  7. curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
  8. curl_setopt ($ch, CURLOPT_HEADER, 0);
  9. curl_exec ($ch);
  10. echo curl_error($ch);
  11. $curl_scraped_page = curl_exec($ch);
  12. curl_close($ch);
  13. $zmiennadoexpldoe = $curl_scraped_page;


Idąc dalej błąd 400 oznacza:
Kod
400 - Bad Request
The syntax of the request was not understood by the server.


Ale czemu hmm. Adres URL jest na pewno poprawny.

Idąc dalej..

Starałem połączyć się bez proxy. Jeżeli robię poprzez funkcję openurl lub curl_get wszystko działa dobrze..
Może prześlę cały kod..
  1. <?php
  2. $p = strip_tags($_GET['page']);
  3. $ser = strip_tags($_GET['search']);
  4. $count = get_source_count('mp3skull_local');
  5. $max = 16;
  6.  
  7. if($count > $max or empty($count)) { $count = $max; }
  8.  
  9. $mp3skull = curl_get("http://mp3skull.com/search.php?q=".$ser."&submit=Search");
  10. $i = 0;
  11.  
  12. while($i++ < $count)
  13. {
  14. $track = explode("<div id=\"song_html\" class=\"show", $mp3skull);
  15. $track = explode("<div id=\"player", $track[$i]);
  16. $track = $track[0];
  17. $url = expstr($track, "<a href=\"http://dc", ".mp3\"");
  18. $url = "http://dc".$url.".mp3";
  19. $search2 = array('mp3','djoles.pl', '--', 'www.', '[]', 'djwitek.org', 'djwitek.prv.pl','djwitek.info');
  20. $replace2 = array('','', '','', '', '', '','');
  21. $name = str_replace($search2, $replace2, strtolower(strip_tags(expstr($track, "<div style=\"font-size:15px;\"><b>", "</b>"))));
  22. $lname = str_replace(' ', '_', $name).".mp3";
  23. $listen = 'name=' . $lname . '&amp;url=' . enc($url);
  24. $download = 'name=' . $lname . '&amp;url=' . enc($url);
  25. $search = array('<br />', 'mins', '0:00 minut', '128 kbps');
  26. $replace = array(' ', 'minut', 'nieokreślone', 'nieokreślone');
  27. $playtime = str_replace($search, $replace,expstr($track, "left\">", "</div>"));
  28.  
  29. if($track){
  30. include("templates/layout_list.php");
  31. }
  32. }
  33. ?>


A gdy chcę poprzez proxy tamtą metodą nie chce ruszyć ani trochę...
  1. $url = "http://mp3skull.com/search.php?q=".$ser."&submit=Search";
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL,$url);
  4. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  5. curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
  6. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  8. curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
  9. curl_setopt ($ch, CURLOPT_HEADER, 1);
  10. curl_exec ($ch);
  11. echo curl_error($ch);
  12. $curl_scraped_page = curl_exec($ch);
  13. curl_close($ch);
  14. $mp3skull = $curl_scraped_page;


Nikt nie jest w stanie pomóc ?

Dalej szukam rozwiązania.. Jak jest ktoś w stanie pomóc to proszę o pomoc...
mat-bi
Może pokombinuj z headerami? Np. dodaj UA.
ones
Ale ogólnie składnia tego kodu jest dobra? Powinno się teoretycznie wyświetlać tzn pobierać dane strony zamiast curl get?

Doszedłem już do tego, że działa jak jest

CURLOPT_HTTPPROXYTUNNEL, 0
Jak daję 1 nie działa, nie wyświetla żadnych wyników.
Agares
Cytat(ones @ 13.07.2011, 10:19:32 ) *
Ale ogólnie składnia tego kodu jest dobra? Powinno się teoretycznie wyświetlać tzn pobierać dane strony zamiast curl get?

Doszedłem już do tego, że działa jak jest

CURLOPT_HTTPPROXYTUNNEL, 0
Jak daję 1 nie działa, nie wyświetla żadnych wyników.

Moja rada jest taka, żebyś poczytał sobie co robią funkcje które wywołujesz i opcje które przy ich pomocy ustawiasz.
amii
A jesteś pewny, że samo proxy działa poprawnie ? Czasami już po paru godzinach publiczne proxy przestają funkcjonować.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.