Has anyone had issues with the iconv_strlen function while running MAMP?
-
How are strings stored in PHP? With a `\0` or they carry a length? – alex Mar 23 '11 at 02:24
-
1They carry a length in bytes, but no encoding. [`iconv_strlen`](http://us2.php.net/manual/en/function.iconv-strlen.php) converts the string across character encodings and then returns the *character* count, as opposed to the byte length. – Charles Mar 23 '11 at 02:59
-
@blacktie24, can you please provide us a sample string that causes issues? You can safely post it here after running it through `rawurlencode` to ensure we get the actual correct bytes. (I have retagged your post.) – Charles Mar 23 '11 at 03:01
-
@Charles Thanks for your clarification. BTW, do you have any further recommended reading on the subject? – alex Mar 23 '11 at 04:42
-
@alex, on what, exactly? I'm sure you've seen [Joel's article](http://www.joelonsoftware.com/articles/Unicode.html), which is of course required reading around here. There's also [this slightly older but still great PHP character encoding FAQ](http://kore-nordmann.de/blog/php_charset_encoding_FAQ.html). Information on PHP's internal string representation is kind of tribal knowledge; someone around here picked apart the PHP source recently to prove that the length is stored. I'll see if I can find it. Might have been Pascal Martin or Gordon. – Charles Mar 23 '11 at 05:11
-
@Charles Just on the internal representation of strings in PHP. Thanks for your reply. – alex Mar 23 '11 at 05:15
-
1@alex, [here's the answer I was thinking of](http://stackoverflow.com/questions/5292325/algorithmic-complexity-of-php-function-strlen/5292334#5292334). Unfortunately I mis-remembered the reference! A ten year old comment in the manual is not going to be authoritative. – Charles Mar 23 '11 at 05:25
4 Answers
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.
- Bug #49267 Linking fails for iconv: "Undefined symbols: _libiconv"
- PHP 5.3.0 on Mac OS 10.6 (Snow Leopard) - Fabien Potencier; 05 Nov 2009
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.

- 193,403
- 52
- 435
- 836

- 176
- 1
- 2
-
user673450, this is the exact issue i'm having. Thx for the info on potential workarounds. – blacktie24 Mar 23 '11 at 19:36
-
I'm having the same problem with iconv_strpos but only in 5.3.5. It works on my other machine with 5.3.2.... so how can this be? – spankmaster79 Apr 06 '11 at 15:32
-
thanks. great to know i'm not going crazy. this is still a problem for me in Mamp Pro 2.0.1. – Steve Aug 02 '11 at 07:48
-
Thanks for the info. MAMP with PHP 5.2 solves the issues I was having with MAMP 2 and Magento (on Lion). – Toby Hemmerling Aug 20 '11 at 19:09
-
3It's finally resolved in MAMP 2.0.2 http://blog-en.mamp.info/2011/08/mamp-pro-2-0-1-released.html – Zifius Aug 23 '11 at 10:25
-
@Zifius can you really confirm this? "PHP problems with icondev now fixed" I don't want to by another version without beeing able to recompile PHP or the problem still existing – spankmaster79 Aug 24 '11 at 09:38
-
1@spankmaster79 yes, my problems with ability to run Magento on PHP 5.3 are gone – Zifius Aug 24 '11 at 16:50
-
great finally.... just bought the licenze.. hope upgrading is as easy as reinstalling – spankmaster79 Aug 24 '11 at 17:06
In case anyone is still having this issue, I struggled for ages with this, but upgrading to the very latest version of MAMP Pro on OSX Lion seemed to work for me.

- 53,861
- 28
- 137
- 147

- 11
- 1
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);
}
?>

- 25,759
- 11
- 71
- 103
According to the MAMP forums, the new update to version 2.x (2.0.2 released on August 17, 2011) resolves the iconv issue. Yes!

- 25,759
- 11
- 71
- 103
-
-
Nobody has to pay to upgrade MAMP. One only needs to pay for MAMP PRO, but not plain MAMP and that has always been the case. – Giacomo1968 Jan 29 '12 at 07:16