[TYPO3-dev] class.tx_impexp.php sets 256m memory_limit without checking php.ini

Sebastiaan Wiersema sebastiaan at buyways.nl
Tue Jun 10 12:25:12 CEST 2008


On Tue, 2008-06-10 at 11:52 +0200, Martin Kutschker wrote:
> Sebastiaan Wiersema schrieb:
> > Hi,
> > 
> > Yesterday I reported the following bug in class.tx_impexp.php:
> > http://bugs.typo3.org/view.php?id=8649
> > 
> > On request of Benjamin Mack I'm sending the patch to this list.
> > 
> > Cheers,
> > Sebastiaan
> > 
> > --
> > 
> > There is no check in class.tx_impexp.php to see if it is necessary to
> > alter the memory_limit setting. Even when the value is altered in
> > php.ini to a higher value (say, 512MB) this is set back to 256MB.
> 
> Yes, that's dull.
> 
> 
> > The following patch should do the trick:
> 
> Will fail if the limit doesn't use the 'm' for megabytes.
> 
> Masi

True. The patch was made in a hurry, I still had to do the export ;) I
made a new one (I'll post it at bugs.typo3.org as well), which addresses
the max_execution_time as well. I know I made it a bit more extensive
than needed (it could all fit in a nice single if-statement), but this
proved a bit more readable.

Cheers,
Sebastiaan



--- typo3/sysext/impexp/class.tx_impexp.php 2007-12-14
15:08:55.000000000 +0100
+++ typo3/sysext/impexp/class.tx_impexp.php 2008-06-10
12:17:01.000000000 +0200
@@ -179,8 +179,34 @@
 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
 require_once (PATH_t3lib.'class.t3lib_refindex.php');
 
- at ini_set('max_execution_time',600);
- at ini_set('memory_limit','256m');
+if (ini_get('max_execution_time') < 600) {
+       @ini_set('max_execution_time',600);
+}
+// Set the memory_limit to a specified minimum (in MB)
+$memory_minimum = 256;
+$memory_limit = ini_get('memory_limit');
+// -1 means no limit
+if ($memory_limit != -1) {
+       switch (strtolower(substr($memory_limit, -1))) {
+               case 'g': // Gigabytes
+                       // Minimum is 1GB, so no need to raise it
+                       break;
+               case 'm': // Megabytes
+                       if (substr($memory_limit, 0, -1) <
$memory_minimum) {
+                               @ini_set('memory_limit',
$memory_minimum.'m');
+                       }
+                       break;
+               case 'k': // Kilobytes
+                       if (substr($memory_limit, 0, -1) <
($memory_minimum * 1024)) {
+                               @ini_set('memory_limit',
$memory_minimum.'m');
+                       }
+                       break:
+               default: // Just bytes
+                       if (ctype_digit($memory_limit) && $memory_limit
< ($memory_minimum * 1024 * 1024)) {
+                               @ini_set('memory_limit',
$memory_minimum.'m');
+                       }
+       }
+}






More information about the TYPO3-dev mailing list