note 118363 added to function.ldap-connect

From: Date: Mon, 23 Nov 2015 10:30:33 +0000
Subject: note 118363 added to function.ldap-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-204210@lists.php.net to get a copy of this message
Hello, Little corrections to nemanja post. - There was a warning if connection is denied by firewall (adding @ before fsockopen) - fclose parameter was incorrect. With this approach, you get a real nice failover functionality, take for an example a company with a dozen of DC-a distributed along distant places, this way your PHP program will always have high availability if at least one DC is active at present. <?php function serviceping($_host, $_port = 389, $_timeout = 1) { $op = @fsockopen($_host, $_port, $errno, $errstr, $_timeout); if (!$op) { echo "KO!"; return 0; } //DC is N/A else { fclose($op); //explicitly close open socket connection return 1; //DC is up & running, we can safely connect with ldap_connect } } function ldap_connect_failover($_domain) { // ##### STATIC DC LIST, if your DNS round robin is not setup //$dclist = array('10.111.222.111', '10.111.222.100', '10.111.222.200'); // ##### DYNAMIC DC LIST, reverse DNS lookup sorted by round-robin result $dclist = gethostbynamel($_domain); foreach ($dclist as $dc) { if (serviceping($dc) == true) { break; } else { $dc = 0; } } //after this loop, either there will be at least one DC which is available at present, or $dc would return bool false while the next line stops program from further execution if (!$dc) { return false; } //user being notified return ldap_connect($dc); } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 194.51.110.132 ---- Manual Page -- http://php.net/manual/en/function.ldap-connect.php Edit -- https://master.php.net/note/edit/118363 Del: integrated -- https://master.php.net/note/delete/118363/integrated Del: useless -- https://master.php.net/note/delete/118363/useless Del: bad code -- https://master.php.net/note/delete/118363/bad+code Del: spam -- https://master.php.net/note/delete/118363/spam Del: non-english -- https://master.php.net/note/delete/118363/non-english Del: in docs -- https://master.php.net/note/delete/118363/in+docs Del: other reasons-- https://master.php.net/note/delete/118363 Reject -- https://master.php.net/note/reject/118363 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204210) next »