473,500 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does the connection time out?

HaLo2FrEeEk
404 Contributor
I'm writing a quick little script to grab some information from Stickam.com, specifically using the "API" they have set up to get a user id from a provided username, and a username from a provided userid. These are both publically accessible pieces of information, so I'm not getting into anything I shouldn't, I'm just using the publically accessible API instead of scraping the HTML.

For some reason I can't explain though, I can't seem to get the contents of the page using PHP. Here's my code:

Expand|Select|Wrap|Line Numbers
  1. $username = @$_GET['username'];
  2. if(!$username) {
  3.   die("no username");
  4.   }
  5.  
  6. $url = "http://www.stickam.com/servlet/ajax/getLiveUser?uname=".$username;
  7. $html = file_get_contents($url, false, $context);
  8.  
  9. echo "<pre>";
  10. echo $html;
  11. echo "</pre>";
But everytime I load this page on my server, I get this response:

Warning: file_get_contents(http://www.stickam.com/servlet/ajax/getLiveUser?uname=[username]) [function.file-get-contents]: failed to open stream: Connection timed out in [file] on line 7

I can load it just fine on my Apache server running on my personal computer, and I can load it in my browser (both IE9 and Firefox), but not on my website. I've tried mimicking the headers that my browser sends and creating a stream context to send with the file_get_contents() call, but so far nothing seems to work.

Any ideas?
Dec 29 '10 #1
4 5385
JKing
1,206 Recognized Expert Top Contributor
Have you tried hard coding a username?

Not really sure why you would get a timeout but I attempted this with a hardcoded username I saw on the homepage and got "[]" as the return string. Tried several usernames with the same result.

Also tried this using curl instead of file_get_contents and had the same result. You may also want to give curl a try.
Dec 29 '10 #2
HaLo2FrEeEk
404 Contributor
I've tried both cURL and file_get_contents, neither work, and cURL is a pain (for me). you'll get a [] if the user is not currently online, otherwise you'll get an array of information about the user.

I don't think hadcoding a user would hep, but I'll try. You can see from the error message that it is indeed resolving the proper URL, and like I said this works perfectly fine on the Apache server installed on my personal computer and run from localhost. I literally wrote the code on my local server, tested it, then uploaded it to my web server and it no longer worked.

I'll try a hardcoded username though, see what I get, hold up...

Nope, same result.

All that happens is the page appears to load for about 10 seconds, then it comes up with that error message.

Obviously something is weird here, I can't imagine that Stickam would ban requests from my server when there are other sites, ike 4hds.com, that poll it way more often and way more heavily.
Dec 29 '10 #3
JKing
1,206 Recognized Expert Top Contributor
What is in your $context variable?

I am able to get both curl and file_get_contents to work both locally and on a test server.
Dec 30 '10 #4
HaLo2FrEeEk
404 Contributor
Right now just a UserAgent string, my UserAgent string:

Expand|Select|Wrap|Line Numbers
  1. $opts = array('http' => array('header' => 'user_agent' => "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
  2. $context = stream_context_create($opts);
And it still doesn't work from my web server, but works perfectly fine from my local server.

I think Stickam blacklisted my server's IP.
Jan 2 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2847
by: Madhivanan | last post by:
Hai, I am using an VB application using SQL Server 2000 as the database. I am using BeginTrans and CommitTrans methods to save data into the SQL Server 2000 Database in the VB Application....
1
1748
by: Kelvin | last post by:
Hi all, Any some tools or sample codes drop down asp script execute time and database connection time ? Thanks.
0
981
by: Amit | last post by:
Hi, My web.config looks like this: .... <authentication mode="Forms"> <forms name=".ASPXAUTH" protection="All" timeout="2"/> </authentication> .... <sessionState mode="InProc"...
0
1100
by: NuB | last post by:
I have a asp.net web application that connects to a database server that is located outside of our building. When I run the web app the initial connection to the database is slow ( around 30-35...
1
1198
by: Pete2004 | last post by:
Is there way to programmatically increase the allowed connection time for an SQL Command operation. I issue a query that executes perfectly, but it does take a long time to complete. When I use...
4
11484
by: maneeshjp | last post by:
Hi to all, I have wrote a jsp-servlet program(using struts) which connects to DB2 via JDBC. I am using Tomcat5.5. JDBC driver as400thinjdbc.jar . DB connection paramaters are <data-sources>...
2
2505
by: maneeshjp | last post by:
Hi to all, I have wrote a jsp-servlet program(using struts) which connects to DB2 via JDBC. I am using Tomcat5.5. JDBC driver as400thinjdbc.jar . DB connection paramaters are <data-sources>...
8
16148
by: fniles | last post by:
Can I change the connection time out in VB.Net 2003 and MS Access (using OLEDbConnection) ? When I use Connect Timeout = 60 in the connectionstring, I get an error "Multiple-step OLE DB operation...
8
10774
dmjpro
by: dmjpro | last post by:
i want to change the default connection time-out value. which is by default 5 minutes. i want to change this value. actually this value is set against a HTTP-HEADER. i just want to know that...
0
1400
by: abhighat4214 | last post by:
Hello All, Actually I wanted to implement a MySQL connection time-out for the data-entry application which I developed in PHP. I just wanted to know is there any function in PHP-MYSQL lib that...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.