[xdebug-general] Re: socket_connect error

From: Derick Rethans <derick[@]xdebug.org>
Date: Wed, 28 Jun 2006 09:37:23 +0200 (CEST)

On Tue, 27 Jun 2006, Sandrio Fontes wrote:

> I'm writing a small php script to replace xdebug client on my web
> application server. my idea is to do remote debug using only a webbrowser.
>
> my script (socket.php):
>
> <?php
> $service_port = "9000";
> $address = "127.0.0.1";
>
> $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
> if ($socket < 0) {
> echo "socket_create() failed: reason: " . socket_strerror($socket) .
> "\n";
> exit();
> } else {
> echo "socket_create = TRUE.\n";
> }
>
> echo "Attempting to connect to '$address' on port '$service_port'...";
> $result = socket_connect($socket, $address, $service_port);
> if ($result < 0) {
> echo "socket_connect() failed.\nReason: ($result) " .
> socket_strerror($result) . "\n";
> exit();
> } else {
> echo "socket_connect == TRUE.\n";
> }
> ?>
>
> the result:
> bossnass:~ # php /www/htdocs/socket.php
> socket_create = TRUE.
> Attempting to connect to '127.0.0.1' on port '9000'...

Of course you can not connect. The IDE/client must *accept* connections,
not initiate them. This is explained here:
http://xdebug.org/docs-dbgp.php#initiating-a-debugging-session . Used
terminology can be found here:
http://xdebug.org/docs-dbgp.php#terminology

Basically instead of doing a socket_connect() you'll need a
socket_listen() and wait for the webserver+php+xdebug to connect to the
client. Instead of using the socket extension I actually suggest to use
the new socket functionality in the streams part of PHP as those
functions are much more stable, for more information see:
http://no.php.net/manual/en/function.stream-socket-server.php
http://no.php.net/manual/en/function.stream-socket-accept.php

regards,
Derick

-- 
Xdebug | http://xdebug.org | xdebug-general@lists.xdebug.org
Received on Wed Jun 28 2006 - 09:37:50 BST

This archive was generated by hypermail 2.2.0 : Mon Jun 25 2018 - 06:00:04 BST