[wp-trac] [WordPress Trac] #14889: Memory Comparison Broken / WordPress Memory Limit

WordPress Trac wp-trac at lists.automattic.com
Mon Jun 6 23:18:36 UTC 2011


#14889: Memory Comparison Broken / WordPress Memory Limit
-----------------------------------------------+---------------------------
 Reporter:  hakre                              |       Owner:
     Type:  defect (bug)                       |      Status:  new
 Priority:  normal                             |   Milestone:  Future
Component:  General                            |  Release
 Severity:  normal                             |     Version:  3.0
 Keywords:  has-patch 3.2-early needs-testing  |  Resolution:
-----------------------------------------------+---------------------------

Comment (by aaroncampbell):

 @chrisbliss: Yep, looks like your way is faster.  However, looking at your
 test script we're really starting to split hairs here.  I hate duplicate
 code, so I'd prefer to see the string->bytes conversion pushed to a
 function rather than duplicated:
 {{{
 function bytes_from_memory_string( $mem ) {
         $unit = strtolower( substr( $mem, -1 ) );
         if ( 'm' == $unit )
                 return $mem * 1048576;
         else if ( 'g' == $unit )
                 return $mem * 1073741824;
         else if ( 'k' == $unit )
                 return $mem * 1024;
         return $mem;
 }

 $memory_limit = @ini_get( 'memory_limit' );

 if ( $memory_limit > -1 ) {
         if ( (float) bytes_from_memory_string( $memory_limit ) < (float)
 bytes_from_memory_string( WP_MEMORY_LIMIT ) )
                 @ini_set( 'memory_limit', WP_MEMORY_LIMIT );
 }

 }}}


 Also, casting to int caused the 7.5G test to fail on several of my test
 environments.  As you can see above, casting to float fixed that issue for
 me.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14889#comment:24>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list