note 64381 added to function.socket-get-option

From: Date: Thu, 13 Apr 2006 05:45:49 +0000
Subject: note 64381 added to function.socket-get-option
Groups: php.notes 
Request: Send a blank email to php-notes+get-107958@lists.php.net to get a copy of this message
I changed X_Crikou's code to functionalize it and make the output easily readable: <?php function sockOpts ( $socket, $realData = FALSE ) { # Returns an array of strings in which the keys are the # option names and the values are the name's value # setting for the passed socket connection. # Created for human-readable output. # If $realData == TRUE, then output actual data # and not a string. $opts=array( "SO_BROADCAST" => SO_BROADCAST, "SO_DONTROUTE" => SO_DONTROUTE, "SO_DEBUG" => SO_DEBUG, "SO_ERROR" => SO_ERROR, "SO_FREE" => SO_FREE, "SO_KEEPALIVE" => SO_KEEPALIVE, "SO_LINGER" => SO_LINGER, "SO_NOSERVER" => SO_NOSERVER, "SO_OOBINLINE" => SO_OOBINLINE, "SO_RCVBUF" => SO_RCVBUF, "SO_RCVLOWAT" => SO_RCVLOWAT, "SO_RCVTIMEO" => SO_RCVTIMEO, "SO_REUSEADDR" => SO_REUSEADDR, "SO_SNDBUF" => SO_SNDBUF, "SO_SNDLOWAT" => SO_SNDLOWAT, "SO_SNDTIMEO" => SO_SNDTIMEO, "SO_TYPE" => SO_TYPE ); foreach ( $opts as $key => $val ) { if ( $realData ) { # Actual data may contain integer or array values $got = socket_get_option( $socket, SOL_SOCKET, $val ); } else{ # Output is converted to strings for printing. # This is the default format. $got = var_export( socket_get_option( $socket, SOL_SOCKET, $val ), 1 ); } $opts[$key] = $got; } return $opts; } # connects to local web server port $sock = socket_create( AF_INET, SOCK_STREAM, SOL_TCP ); socket_connect( $sock, "127.0.0.1", 80 ); # print the values of sockOpts() returned as strings print "Complete string values: <br />"; print nl2br( var_export( sockOpts( $sock ), 1 ) ); # this will print some comparisson usage $optsData = sockOpts( $sock, TRUE ); $optsStr = sockOpts( $sock ); # show a data value print "SO_RCVTIMEO Data value: <br />"; print nl2br( var_export( $optsData["SO_RCVTIMEO"], 1 ) ); # show a string value print "SO_RCVTIMEO String value: <br />"; print $optsStr["SO_RCVTIMEO"] . "<br />"; # show an example of an array value within a data value print "SO_RCVTIMEO Data value for 'sec': <br />"; print nl2br( var_export( $optsData["SO_RCVTIMEO"]["sec"], 1 ) ); socket_close( $sock ); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 67.188.177.135 ---- X-Spam-Status: No, hits=4.0 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE,UPPERCASE_25_50 autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.socket-get-option.php Edit -- http://master.php.net/note/edit/64381 Del: integrated -- http://master.php.net/note/delete/64381/integrated Del: useless -- http://master.php.net/note/delete/64381/useless Del: bad code -- http://master.php.net/note/delete/64381/bad+code Del: spam -- http://master.php.net/note/delete/64381/spam Del: non-english -- http://master.php.net/note/delete/64381/non-english Del: in docs -- http://master.php.net/note/delete/64381/in+docs Del: other reasons-- http://master.php.net/note/delete/64381 Reject -- http://master.php.net/note/reject/64381 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107958) next »