3

I'm trying to debug the PHP function stream_socket_client but I don't really know how. This is the code that I'm having trouble with:

        $this->socket = @stream_socket_client(
            $remote, $errno, $errstr,
            $this->request->getConfig('connect_timeout'),
            STREAM_CLIENT_CONNECT, $context
        );
        if (!$this->socket) {
            throw new HTTP_Request2_ConnectionException(
                "Unable to connect to {$remote}. Error: {$errstr}",
                0, $errno
            );
        }

The exception is thrown and the error reads "Unable to connect to tcp://www.dropbox.com:80. Error: Connection timed out". This code comes from a very popular Wordpress plugin that's been well tested. The server I'm working on has some quirks, e.g. I'm allowed to upload or remove files via PHP etc. so I'm wondering if there are any PHP settings that could prevent stream_socket_client from working and how I can check what those settings are for my server.

C. E.
  • 10,297
  • 10
  • 53
  • 77
  • 1
    Perhaps the server has outgoing http connections blocked? Firewall issue? Do you have shell access to the server? try doing a "telnet www.dropbox.com:80" at the command line and see if that connects. If not, then it's not a PHP problem. – Marc B Aug 19 '11 at 21:24
  • 1
    Sorry, I don't have shell access. This isn't my server, I'm merely installing something for somebody and although it's not on a web hotel, the setup is like that with control panel and everything... – C. E. Aug 19 '11 at 21:33

1 Answers1

5

Try to check allow_url_fopen.

This option enables the URL-aware fopen wrappers that enable accessing URL object like files.

See: https://php.net/manual/en/filesystem.configuration.php

kenorb
  • 155,785
  • 88
  • 678
  • 743
Andrej
  • 7,474
  • 1
  • 19
  • 21
  • 1
    According to phpinfo, allow_url_fopen is "on." – C. E. Aug 19 '11 at 21:32
  • 1
    Ok. Could you try fsockopen and check errors? Maybe this error isn't related to streams and related to firewall or something else. – Andrej Aug 19 '11 at 21:39
  • 1
    Alright, for example fsockopen( 'www.google.com', 80 ); doesn't seem to work. Also connection time out, as well as for dropbox.com naturally. I don't know what this means though? What in my hosting environment do I need to change? – C. E. Aug 19 '11 at 21:57
  • 1
    What type of hosting do you use? – Andrej Aug 19 '11 at 22:01
  • 1
    There are two causes: 1. DNS problem 2. hoster doesn't allow to make external requests. – Andrej Aug 19 '11 at 22:08
  • I'll continue this discussion with my host then, thank you very much for your help. – C. E. Aug 19 '11 at 22:14