iconv_strlen function causing execution timeout, running on MAMP
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
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.
How to use Apple's php 5.3 with MAMP
I'm not sure this leave a whole lot of value in the MAMP, but you probably are best served compiling your own php and apache.
http://fabien.potencier.org/article/37/php-5-3-0-on-mac-os-10-6-snow-leopard
Zend_validate isValid() get stuck fatalError Maximum execution time of 30 seconds exceeded in /library/Zend/Validate/Hostname.php on line 608
Source: http://forum.mamp.info/viewtopic.php?f=2&t=12189"I actually just found the answer to this one:
The version of PHP 5.3 that ships with MAMP has a bug in
iconv_strlen() that causes a "do { ... } while (false);" loop in the
validator to run infinitely. I just switched my PHP version to 5.2, as
it's closer to production anyway, and it works. If you need the 5.3,
though, you will have to upgrade your PHP installation in MAMP. I
haven't tried it, but the following link was highly recommended:http://www.davidgolding.net/cakephp/upgrading-php-in-mamp.html
Hope that all helps."
Algorithmic complexity of PHP function strlen()
O(1) since the length is stored as an attribute: source
However, this trivia is worth countering with a discussion about micro-optimising theatre, as kindly provided by our hosts here and here; read those two links and you'll find a good talking point to change the momentum of the conversation next time similar questions come up, regardless of whether you know the particular answer!
How the interviewer reacts to your tangent will tell you a lot about how much you want to work with them..
Related Topics
Laravel and Multi-Sessions from the Same Browser
How to Pass an Array of Checked/Unchecked Checkbox Values to PHP Email Generator
Customizing My-Account Addresses Fields in Woocommerce 3
Laravel Customized Session.Lifetime at User Level
File_Get_Contents('Php://Input') Always Returns an Empty String
How to Call a Static Method on a Variable Class
Converting PHP Array of Arrays into Single Array
How Would You Transform a Pre-Existing Web App into a Multilingual One
Random Float Number Between 0 and 1.0 PHP
PHP Exec() Command: How to Specify Working Directory
How to Sort Null Values Last Using Eloquent in Laravel
PHP - What's the Benefit of Unsetting Variables
Get User Data Using Access Token in Laravel Passport Client App
PHP Sort a Multidimensional Array by Number of Items
What's the Difference Between Post and Raw Post in PHP at All