This probably isn't a PHP issue. Leave the PHP aside for now.
Try setting up your sudo, then su in as the unpriviliged web server owner (possibly "nobody" or "apache") and see if you can execute the script.
To setup the sudo, you need to run "visudo" as a privilged user, within visudo, you could include a line something like:
nobody ALL = /var/www/scripts/scriptname
This will allow the "nobody" user to run scriptname.
Now "su -l nobody" and check that you can indeed run the script.
Note, "su -l nobody" may not work as logins may be disabled for "nobody". If this is the case, repeat the vimsudo and substitute a different unpriviliged user.
Once you've got it working, change it back to nobody, or whoever runs your httpd, and retry from within PHP.
Hope this helps.