I had this working before :
echo ini_get(\"memory_limit\").\"\\n\";
ini_set(\"memory_limit\",\"256M\");
echo ini_get(\"memory_limit\").\"\\n\";
Ubuntu 10.04 comes with the Suhosin patch only, which does not give you configuration options. But you can install php5-suhosin to solve this:
apt-get update
apt-get install php5-suhosin
Now you can edit /etc/php5/conf.d/suhosin.ini and set:
suhosin.memory_limit = 1G
Then using ini_set will work in a script:
ini_set('memory_limit', '256M');