
Second, because it would mean your php scripts are sharing a pasteboard with your user session - you'd go to copy something from one program to another, and find you were pasting in something from the web script, not what you'd copied. First, because it wouldn't be able to join until you logged in, and would break as soon as you logged out web service really should run independently of who happens to be logged in at the time. There might be a way to join a particular login session (involving launchctl bsexec), but for a web service this would be a bad idea. launchd runs apache in a system context, so there's no pasteboard server available (note that even though apache switches users to cwd, that's not the same as joining your login session). It's not a privilege thing, it's because pbcopy and pbpaste need a pasteboard server (essentially, a background program that holds the pasteboard), and that's run as part of a user login session. They don't seem to work until I manually restart apache. I also have similar experiences with running other system commands with exec or shell_exec like ssh.

However, if I stop XAMPP and restart it (using XAMPP Control), then it works as expected and the third line's result is 1234. Well, if I just let the computer start up, and if I run a php script with these commands, here is what I get:

I have set the apache user set to be the same as my account name in nf User cwd I use Mac OS X and use Launchd to automatically start XAMPP.
