Note that on unix, if your target user does not have a valid shell, some php functions (eg: tempnam) will not work correctly:
$ grep www-data /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
$ cat test.php
#!/usr/bin/php -q
<?php
$info=posix_getpwnam("www-data");
$id=$info["uid"];
$file=tempnam("/tmp","something");
print "PRE SetUID: $file\n";
$SETUID=posix_setuid($id);
$file=tempnam("/tmp","something");
print "POST SetUID: $file\n";
?>
$ sudo ./test.php
PRE SetUID: /tmp/somethingrsb1qZ
POST SetUID: