Hey Joseluis,
I also mainly use the php native function memory_get_usage(), but it has an fallback that could be interesting for you.
I found it on stackoverflow:
stackoverflow.com/questions/2290611
...
The post of Alix Axel also reads the memory usage the running OS determines:
exec('ps -eo%mem,rss,pid | grep ' . getmypid(), $output);
And have a look at the comment of greg on Alix' post...
I look forward to your second part