Unable to connect to host from a specific server


Hi there,

I’m using PHP and from one of my servers I always get the same error code and message when creating the consumer.

– Message: Unexpected APIError code: 7 [couldn’t connect to host]

I’m wondering if it is a specific PHP module that is required? I reckon it must either be a missing module or a firewall issue, but if it is just using HTTP streaming, then it shouldn’t be a firewall issue. I’ll check that with my host, just in case.

If someone could provide me with some information on what modules are required though, that would be a great help. I could then check them against my phpinfo.

Thanks in advance



Which version of the library are you using? We pushed the newest version to the Github repo a couple of days ago. Also, which version of PHP are you using? We require 5+ with JSON, or 5.2+ which includes JSON support

It sounds like it could be some domain name issue there - our client library is completely stand-alone, and does not require any external libraries. 


Hi Jason,

Thanks for getting back to me. The Client library is completely up to date - downloaded yesterday.
We are running php v5.3.4
I have put a phpinfo page here temporarily if you wish to check:




I’ve done a bit more digging around and it is the Curl command in the ApiClient.php that is failing. I’m checking with our host that Curl is properly setup.

The response I’m getting from Curl is:

resource(92, curl)

’url’ => string ‘http://api.datasift.com/compile.json’ (length=36)
‘content_type’ => null
’http_code’ => int 0
’header_size’ => int 0
’request_size’ => int 0
’filetime’ => int -1
’ssl_verify_result’ => int 0
’redirect_count’ => int 0
’total_time’ => float 0
’namelookup_time’ => float 0.00021
’connect_time’ => float 0
’pretransfer_time’ => float 0
’size_upload’ => float 0
’size_download’ => float 0
’speed_download’ => float 0
’speed_upload’ => float 0
’download_content_length’ => float 0
’upload_content_length’ => float 0
’starttransfer_time’ => float 0
’redirect_time’ => float 0



It looks like cURL is operating properly, otherwise you would not get back the default return object you are seeing. It sounds like it must be an issue with your host - possibly something to do with the firewall blocking requests. Have you heard anything back from them yet?


Hi Jason,

Thanks, yes I have heard back and they are blocking all outgoing connections through a proxy.

I’ve requested they open up a channel to datasift to allow me to get through. Hopefully this will be in place by Monday - fingers crossed!



Brilliant. Please let us know if this solves your problem


It almost did!

They provided me with a Proxy Server address, username and password.

I added these to the Curl command in ApiClient.php and Curl can now access your servers just fine.

Unfortunately, the HTTP.php is using fsockopen to consume the feed. I have seen some information on how to use fsockopen with a proxy, but quite honestly, I’m struggling to see how to implement it within your library.

Have you come across this before? Do you have a version that takes account of a proxy server?

I’ll keep digging around in the code for now, but if you could let me know if you’re able to help on this one, I’d very much appreciate it.




Hmmm - ok - I think I’ve modified the library to allow for an optional proxy server to be specified in the User object.
Just waiting for the host to add stream.datasift.com to the list of allowed endpoints and hopefully this will solve it.

I’ve made it an optional addition, so if it works, I’ll send you the modified library to add to your repository. Should be backwards compatible and should work with or without Proxy Authentication.