smalot / cups-ipp

CUPS Implementation of IPP - PHP Client API
GNU General Public License v2.0
106 stars 56 forks source link

Can't create socket #13

Closed nashsaint closed 4 years ago

nashsaint commented 4 years ago

I am not sure if this issue is directly related to this package but I can't find solutions, so here asking for support. Your List Printers code throws an error No such file or directory and is thrown from Client.php

protected function createSocket(RequestInterface $request, $remote, $useSsl)
    {
        $errNo = null;
        $errMsg = null;
        $socket = @stream_socket_client($remote, $errNo, $errMsg, floor($this->config['timeout'] / 1000), STREAM_CLIENT_CONNECT, $this->config['stream_context']);

        if (false === $socket) { \\  <-------- THROWS AN ERROR HERE!
            throw new ConnectionException($errMsg, $request);
        }

        stream_set_timeout($socket, floor($this->config['timeout'] / 1000), $this->config['timeout'] % 1000);

        if ($useSsl && false === @stream_socket_enable_crypto($socket, true, $this->config['ssl_method'])) {
            throw new SSLConnectionException(sprintf('Cannot enable tls: %s', error_get_last()['message']), $request);
        }

        return $socket;
    }
chriskonnertz commented 4 years ago

Actually this file is not the Client class of smalot/cups but it is this one: vendor/php-http/socket-client/src/Client.php

However: This message might be thrown if you just create the client object like this: $client = new \Smalot\Cups\Transport\Client(), while the CUPS server is not running on the same machine as the PHP code. Try this instead: $client = new \Smalot\Cups\Transport\Client("username", "password" ["remote_socket" => "tcp://remote_ip:631"]) (replace "remote_ip" with the actual IP )

nashsaint commented 4 years ago

Thank @chriskonnertz