Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL sometimes works, sometimes doesn't

Tags:

http

php

curl

So this is the situation I have at hand. I make a curl request from php like this:

$ch = curl_init ( $url );
curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0' );
curl_setopt ( $ch, CURLOPT_HEADER, true );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
curl_setopt ( $ch, CURLOPT_VERBOSE, true );
$header = curl_exec ( $ch );
curl_close ( $ch );

The URL is a short url that redirects. The interesting part is that this happens only with a short url from ift.tt. Sometimes it will get response and sometimes it just hangs at the request. This is what it looks when it hangs:

* About to connect() to ift.tt port 80 (#0)
*   Trying 69.58.188.49... * connected
* Connected to ift.tt (69.58.188.49) port 80 (#0)
> GET /1K0Hs73 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0
Host: ift.tt
Accept: */*

Any ideas as to why it does that? It was working just fine a few days ago. And nothing was changed on my part.

like image 934
dsthetics Avatar asked Jun 30 '26 10:06

dsthetics


1 Answers

Found a solution. Hope this helps someone down the road. Turns out that I made one too many request or something and the IP got banned or restricted, not quite sure. Anyway, adding a proxy to the request fixed the problem.

like image 181
dsthetics Avatar answered Jul 03 '26 01:07

dsthetics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!