Thank you for all replies, recommending me to try other options. The point is that the same script WORKS when ran by root (in a cron task) and fails when ran in the browser. Permission is 755 to be run in the browser).
I would like to understand what's going wrong with this :)