Issue with GeSHI and CakePHP

So today I was having an issue where, for some reason, an incredibly long script in our script repository built using CakePHP would not display the GeSHI syntax-highlighted code. I tore apart the code looking for an answer and the only unique attribute to this script was its very long length (around 1k lines, over 50k characters). I eventually narrowed it down to the preg_replace that was being used in the CakePHP wrapper for GeSHI I was using and discovered that the pcre.backtrack_limit was too low at the default of 10000 (10 thousand). I upped the limit to 10000000 (10 million) and it’s now able to display the syntax highlighted code without issue.

Just thought I’d make a quick post because I could not find another blog with this solution. Hope this helps someone else in a similar predicament!

Total Memory on a Xen Node

I ran into an interesting issue the other day that I figured I’d make a post about in order for others. Since my company is getting more into Xen Hosting, I’ve tried to be at the forefront of the virtualization software for the company. We did run into an interesting issue though the other day when it came to determining the total amount of memory on a hardware node. Since we set up the Domain-0 to use only 512MB of memory, we were having a tough time determining how much total RAM is in the server. After googling for awhile and asking some co-workers, I discovered the following command:

xm info

This command shows quite a few interesting metrics including the total memory for the server. Using this I was able to easily discern the total amount of memory and write a quick script to compute total amount of memory:

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
 
total_memory=$(xm info | grep total_memory | awk '{print $3}')
remaining=$(xm info | grep free_memory | awk '{print $3 - 512}')
used_memory=$((total_memory-remaining))
 
 
echo -e 'Total Memory:\t'$total_memory'MB ('$((total_memory/1024))'GB)'
echo -e 'Memory Used:\t'$used_memory'MB ('$((used_memory/1024))'GB)'
echo -e 'Remaining:\t'$remaining'MB ('$((remaining/1024))'GB)'

Hope this helps anyone else trying to figure out accurate Xen Memory usage