php.ini settimelimit,PHP-set_time_limit()和ini_set('max_execution_time',...)之间的区别...

两种模式“ set_time_limit(5)”和“ ini_set('max_execution_time','5')”都重置时间,这是一个实用而清晰的示例:

//-----------------------------------------------------------

//test "max_execution_time":

ini_set('max_execution_time', 5);

for ($i=0; $i<3; $i++) {

sleep(1);

}

ini_set('max_execution_time', 5);

for ($i=0; $i<3; $i++) {

sleep(1);

}

echo '
';

echo 'done with max_execution_time';

//-----------------------------------------------------------

//test "set_time_limit":

set_time_limit(5);

for ($i=0; $i<3; $i++) {

sleep(1);

}

set_time_limit(5);

for ($i=0; $i<3; $i++) {

sleep(1);

}

echo '
';

echo 'done with set_time_limit';

所有“ for”成功完成,这表示在所有情况下时间都已重置,问候

该代码仅在Windows上适用。PHP Linux中的睡眠时间不占用执行时间例如在linux中:

set_time_limit(2);

for($i=0; $i<10; $i++)

{

echo ("$i \n");

sleep(1);

}

`将会呈现

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

但在Windows上使用默认配置的相同代码将显示

1 | 2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Java中使用LDAP查询同名用户的代码示例: ```java import javax.naming.*; import javax.naming.directory.*; public class LDAPSearch { public static void main(String[] args) { String searchFilter = "(&(objectClass=user)(cn=John Smith))"; // LDAP搜索过滤器 String[] requiredAttributes = {"cn", "mail", "telephoneNumber"}; // 查询返回的属性 // LDAP连接参数 String ldapUrl = "ldap://ldap.example.com:389"; String ldapBaseDn = "dc=example,dc=com"; String ldapUsername = "cn=admin,dc=example,dc=com"; String ldapPassword = "adminpassword"; // 创建LDAP连接 Hashtable<String, String> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapUrl); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, ldapUsername); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); try { // 连接LDAP服务器 DirContext ctx = new InitialDirContext(env); // 执行搜索 NamingEnumeration<SearchResult> results = ctx.search(ldapBaseDn, searchFilter, getSimpleSearchControls(requiredAttributes)); // 处理搜索结果 while (results.hasMore()) { SearchResult result = (SearchResult) results.next(); Attributes attrs = result.getAttributes(); Attribute attr = attrs.get("cn"); String cn = (String) attr.get(); attr = attrs.get("mail"); String mail = (String) attr.get(); attr = attrs.get("telephoneNumber"); String telephoneNumber = (String) attr.get(); System.out.println("cn: " + cn + ", mail: " + mail + ", telephoneNumber: " + telephoneNumber); } // 关闭LDAP连接 ctx.close(); } catch (NamingException e) { e.printStackTrace(); } } // 获取LDAP搜索控制器 private static SearchControls getSimpleSearchControls(String[] attributes) { SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); controls.setTimeLimit(30000); controls.setReturningAttributes(attributes); return controls; } } ``` 请注意,你需要替换代码中的LDAP连接参数和搜索过滤器,以适应你的LDAP服务器和搜索需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值