When PHP run through Apache, the unix user is that of Apache. Eg. www or something similar. When you run a script from the command line, it is run as the current user. On unix systems, files have three types of permissions; user, group and global. Each of these roles can have read, write or execute rights. If you create a file under one user and set the permissions so that other users can access them, well then other users can't access them. You can solve it by putting both users in the same group, set the group ownership to this for the files that need to be shared and finally set group permissions to the same as user permissions (read+write for files and read+write+execute for directories).
Oh, and if you have open_basedir or safe_mode turned on for PHP, things gets a bit more complicated.