Skip to content

Commit 5f751c4

Browse files
committed
Merge branch 'feature/add-memory-limit' into develop
Fix #6
2 parents bcad0aa + 5f96260 commit 5f751c4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

PHPCtags.class.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

phpctags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $options = getopt('f:',array(
1818
'fields::',
1919
'format::',
2020
'version',
21+
'memory::',
2122
));
2223

2324
if(!isset($options['debug'])) {
@@ -41,6 +42,8 @@ if(!isset($options['excmd']))
4142
$options['excmd'] = 'pattern';
4243
if(!isset($options['format']))
4344
$options['format'] = 2;
45+
if(!isset($options['memory']))
46+
$options['memory'] = '128M';
4447
if(!isset($options['fields'])) {
4548
$options['fields'] = array('n', 'k','s', 'a');
4649
} else {

0 commit comments

Comments
 (0)