简体   繁体   English

iconv_strlen函数导致执行超时,在MAMP上运行

[英]iconv_strlen function causing execution timeout, running on MAMP

运行MAMP时有没有人遇到过iconv_strlen函数的问题?

I have been having a timeout issue with it, but not with any exceptions being thrown. 我一直遇到超时问题,但没有抛出任何异常。 I'm working on a Zend Framework site. 我正在开发Zend Framework网站。 By following the debugger deep into the guts, I tracked the problem down to the use of iconv_strlen. 通过深入调试调试器,我将问题跟踪到iconv_strlen的使用。 It's not being called on any strange string, it's a simple function being used to validate a hostname. 它没有被任何奇怪的字符串调用,它是一个用于验证主机名的简单函数。

To verify the issue, I tried a simple iconv_strlen("test", 'UTF-8'); 为了验证这个问题,我尝试了一个简单的iconv_strlen(“test”,“UTF-8”); This causes the error to come up - endless spinning loader in browser but no error log message, and the script goes beyond the max execution time. 这会导致错误出现 - 在浏览器中无限旋转加载器但没有错误日志消息,并且脚本超出了最大执行时间。 It seems that this is an uncaught big in this version of PHP. 在这个版本的PHP中,这似乎是一个未被捕获的大事。

My colleague found this article which might address the issue. 我的同事发现这篇文章可能会解决这个问题。 I'm on a Mac OS X machine updated to the latest Snow Leopard, which is 10.6. 我在Mac OS X机器上更新到最新的Snow Leopard,即10.6。 It seems that this is a known bug and there is a workaround if you build your own php or use the built in Apple version or use ports. 这似乎是一个已知的错误,如果你构建自己的PHP或使用内置的Apple版本或使用端口,有一个解决方法。

Long story short, you can delve into recompiling your own php with the above patch, but this kind of defeats the point of MAMP in the first place. 长话短说,你可以用上面的补丁深入研究重新编译自己的php,但这种方式首先打败了MAMP。

The quickest solution is simply either never use iconv_strlen() (or any of the iconv_ functions) - and this is not an option if you use Zend Framework - or else revert MAMP to use php 5.2. 最快的解决方案就是永远不要使用iconv_strlen()(或任何iconv_函数) - 如果你使用Zend Framework,这不是一个选项 - 或者还原MAMP使用php 5.2。

Until MAMP begins including php source files and providing a method by which to easily recompile the php bundled with all of the necessary libraries, this is will necessarily remain a limitation of the package. 直到MAMP开始包含php源文件并提供一种方法,通过该方法可以轻松地重新编译与所有必需库捆绑在一起的php,这必然是包的限制。 MAMP works great until you get to the point where you need to recompile php. MAMP工作得很好,直到你需要重新编译php。 When that happens, it's far easier to simply use ports. 当发生这种情况时,简单地使用端口要容易得多。

如果有人仍然遇到这个问题,我已经挣扎了很多年了,但升级到OSX Lion上最新版本的MAMP Pro似乎对我有用。

wbond, you have it a bit mixed up. wbond,你有点混淆了。 MAMP 1.9.4 works 100% fine. MAMP 1.9.4 100%罚款。 It's any version of MAMP from 1.9.5 to 2.0.1 that contains the “iconv” issue. 它是从1.9.5到2.0.1的任何版本的MAMP,包含“iconv”问题。 Also, I tested your solution in PHP 5.3.6 in MAMP 2.0.1 and it doesn't work. 另外,我在MAMP 2.0.1中使用PHP 5.3.6测试了您的解决方案,但它不起作用。 The only solution is roll back to MAMP 1.9.4 or use latest MAMP but roll PHP back to 5.2.x. 唯一的解决方案是回滚到MAMP 1.9.4或使用最新的MAMP,但将PHP回滚到5.2.x.

<?php 

$str = 'Hello, world!';
$str = iconv_function('UTF-8', 'UTF-8//IGNORE', $str);
echo $str;

function iconv_function ($in_charset, $out_charset, $str) {
  return iconv($in_charset, $out_charset, $str);
}

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM