File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -225,9 +225,32 @@ private function render($structs, $options)
225225
226226 public function export ($ file , $ options )
227227 {
228+ // if the memory limit option is set and is valid, adjust memory
229+ if (isset ($ options ['memory ' ])) {
230+ $ memory_limit = trim ($ options ['memory ' ]);
231+ if ($ this ->isMemoryLimitValid ($ memory_limit )) {
232+ ini_set ('memory_limit ' , $ memory_limit );
233+ }
234+ }
228235 //@todo Check for existence
229236 $ this ->mFile = $ file ;
230237 $ structs = $ this ->struct ($ this ->mParser ->parse (file_get_contents ($ this ->mFile )), TRUE );
231238 echo $ this ->render ($ structs , $ options );
232239 }
240+
241+ private static function isMemoryLimitValid ($ memory_limit ) {
242+ if ($ memory_limit == "-1 " ) {
243+ // no memory limit
244+ return true ;
245+ } elseif (is_numeric ($ memory_limit ) && $ memory_limit > 0 ) {
246+ // memory limit provided in bytes
247+ return true ;
248+ } elseif (preg_match ("/\d+\s*[KMG]/ " , $ memory_limit )) {
249+ // memory limit provided in human readable sizes
250+ // as specified here: http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
251+ return true ;
252+ }
253+
254+ return false ;
255+ }
233256}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ $options = getopt('f:',array(
1818 'fields:: ' ,
1919 'format:: ' ,
2020 'version ' ,
21+ 'memory:: ' ,
2122));
2223
2324if (!isset ($ options ['debug ' ])) {
@@ -41,6 +42,8 @@ if(!isset($options['excmd']))
4142 $ options ['excmd ' ] = 'pattern ' ;
4243if (!isset ($ options ['format ' ]))
4344 $ options ['format ' ] = 2 ;
45+ if (!isset ($ options ['memory ' ]))
46+ $ options ['memory ' ] = '128M ' ;
4447if (!isset ($ options ['fields ' ])) {
4548 $ options ['fields ' ] = array ('n ' , 'k ' ,'s ' , 'a ' );
4649} else {
You can’t perform that action at this time.
0 commit comments