r54356 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54355‎ | r54356 | r54357 >
Date:11:18, 4 August 2009
Author:demon
Status:resolved (Comments)
Tags:
Comment:
Better patch for parsing PHP's memory limits from OverlordQ.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -3195,11 +3195,16 @@
31963196
31973197 /* Parse PHP's silly format for memory limits */
31983198 function wfParseMemoryLimit( $memlimit ) {
3199 - $n = intval( $memlimit );
3200 - if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
3201 - $n = intval( $m[1] * (1024*1024) );
3202 - }
3203 - return $n;
 3199+ $last = strtolower($memlimit[strlen($memlimit)-1]);
 3200+ $val = intval( $memlimit );
 3201+ switch($last) {
 3202+ case 'g':
 3203+ $val *= 1024;
 3204+ case 'm':
 3205+ $val *= 1024;
 3206+ case 'k':
 3207+ $val *= 1024;
 3208+ return $val;
32043209 }
32053210
32063211 /* Get the normalised IETF language tag

Follow-up revisions

RevisionCommit summaryAuthorDate
r54416Follow up to r54414 and r54356. Hopefully catches all of the edge cases of er...overlordq01:33, 5 August 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   22:06, 4 August 2009

Syntax error fixed in r54364.

Notice when no memory limit in use remains:

> return wfParseMemoryLimit(); Notice: Uninitialized string offset: -1 in /Library/WebServer/Documents/trunk/includes/GlobalFunctions.php on line 3198 0

Looks like it may also fail if whitespace ends up on the value...

http://us3.php.net/manual/en/function.ini-get.php example explicitly includes the trim(), but will fail the same way on the empty case. :)

Note that we _should_ see -1 if the limit is disabled, but ini_set lets you feed it any crap you like. :P

#Comment by Brion VIBBER (talk | contribs)   22:07, 4 August 2009

Ugh... looks like if you give ini_set an invalid value ("" or "50m " with final space) you end up with a de-facto memory limit of 250k, which is nigh-useless. :)

Status & tagging log