Haven't tried it yet, but you're on the right track. For just one process, you could try to set the limits via ulimits and then start that process
$this->bbcode_second_pass_code('', '
~ ulimit -n
1024
~ ulimit -n 2048
~ ulimit -n
2048
')
To makeit permanent, you may need to set it also in /etc/security/limits.conf. Check
https://wiki.archlinux.org/index.php/Limits.conf on archlinux wiki.