|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-05 13:54 UTC] ryan dot brothers at gmail dot com
Description:
------------
I am trying to simulate a LDAP server timing out. I'm setting the options LDAP_OPT_NETWORK_TIMEOUT and LDAP_OPT_TIMELIMIT, but the script runs indefinitely without timing out.
In one ssh session, I am running the following command to simulate a socket listener:
nc -l 1234
If I run the below script in a second ssh session, it runs forever and never times out.
Is there a way to have this script timeout after a certain number of seconds?
Test script:
---------------
<?php
$ldap = ldap_connect('127.0.0.1:1234');
ldap_set_option($ldap, LDAP_OPT_NETWORK_TIMEOUT, 3);
ldap_set_option($ldap, LDAP_OPT_TIMELIMIT, 3);
ldap_bind($ldap);
Expected result:
----------------
Script times out in 3 seconds.
Actual result:
--------------
Script never times out.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 05:00:02 2025 UTC |
I can’t reproduce this, I tried your script, I got «PHP Warning: ldap_connect(): Could not create session handle: Bad parameter to an ldap routine in /tmp/test.php on line 3» So I replaced the call to ldap_connect by «$ldap = ldap_connect('127.0.0.1:1234');» I launched «nc -l 1234» in a shell, in an other one the PHP script, I only got «PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in /tmp/test.php on line 8» immediatly, not even after 3 seconds. Not sure how to test this otherwise…I meant I replaced it by «$ldap = ldap_connect('localhost', 1234);», sorry.This doesn't work for ldaps protocol. Here is my code: <?php $ldap = ldap_connect('ldaps://127.0.0.1:636'); ldap_set_option($ldap, LDAP_OPT_NETWORK_TIMEOUT, 3); ldap_set_option($ldap, LDAP_OPT_TIMELIMIT, 3); ldap_set_option($ldap, LDAP_OPT_TIMEOUT, 3); ldap_bind($ldap); ?> This never timeout.Connection timeouts must be set before connecting. Set LDAP_OPT_NETWORK_TIMEOUT globally before calling ldap_connect() by passing null in place of a connection. ldap_set_option(null, LDAP_OPT_NETWORK_TIMEOUT, 3); ldap_connect('127.0.0.1:1234'); Meanwhile ldap_bind() is something else.For ldap protocol, I did the similar code: <?php $ldap = ldap_connect('ldap://127.0.0.1:389'); ldap_set_option($ldap, LDAP_OPT_NETWORK_TIMEOUT, 3); ldap_set_option($ldap, LDAP_OPT_TIMELIMIT, 3); ldap_set_option($ldap, LDAP_OPT_TIMEOUT, 3); ldap_bind($ldap); ?> This times out in 3 seconds. How could you set timeout before ldap_connect, if $ldap is not set by ldap_connect call?