简体   繁体   中英

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. By following the debugger deep into the guts, I tracked the problem down to the use of 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'); 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.

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. 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.

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.

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.

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 works great until you get to the point where you need to recompile php. When that happens, it's far easier to simply use ports.

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

wbond, you have it a bit mixed up. MAMP 1.9.4 works 100% fine. It's any version of MAMP from 1.9.5 to 2.0.1 that contains the “iconv” issue. Also, I tested your solution in PHP 5.3.6 in MAMP 2.0.1 and it doesn't work. The only solution is roll back to MAMP 1.9.4 or use latest MAMP but roll PHP back to 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);
}

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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