Put this in a file "a.php" and execute it. It works just fine:
#!/usr/bin/php
<?php
$p = popen('xclip -i -selection clipboard', 'w');
fwrite($p, 'Hello Word');
pclose($p);
Now make a file "b.php" and execute it:
#!/usr/bin/php
<?php
passthru('./a.php');
It hangs forever. Why?
(If you do not have xclip, you can install it with apt-get install xclip)