views:

78

answers:

2

hi all

anybody knows if its possible to retrieve some error info (like getsockopt SO_ERROR in C) if an async connect like the following fails btw: im not using the socket extension cause streams provide an ssl wrapper

<?php
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$destination = "tcp://92.247.12.242:8081";
$socket = stream_socket_client($destination, $errno, $errstr,
                                         10, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT, $ctx);a
// plain socket
var_dump($socket);
// no error as expected
var_dump($errno);
var_dump($errstr);

stream_set_blocking($socket, false);

/* Prepare the read array */
$read   = array($socket);
$write  = array($socket);
$except = NULL;
if (false === ($num_changed_streams = stream_select($read, $write, $except, 10))) {
    var_dump("select failed?");
    /* Error handling */
} elseif ($num_changed_streams > 0) {

    /* At least on one of the streams something interesting happened */
    var_dump("event");
    // read fails, so the connect fails but why?
    $result = stream_socket_recvfrom($socket, 1024);
    var_dump($result);
    // no error again
    var_dump($errno);
    var_dump($errstr);
    // nothing interesting
    var_dump(stream_get_meta_data($socket));
}
// wont get called
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
    $args = func_get_args();
    var_dump($args);
}

thx

A: 

As far as I understand errors in stream functions should generate PHP warning messages. I think the only way would be to trap these using set_error_handler() and process them there.

m1tk4