function MultiHandlesWrite($filehandle,$stringtowrite){
for($i=0;$i<=count($filehandle);$i++){
fwrite($filehandle[$i],$stringtowrite);
}
}
Above function will help you to write multi handle same time
you can use like as below , it is used for standand output , temp file and test.txt as we;;
$fps['file'] = fopen('test.txt','w') ;
$fps['screen'] = fopen('php://stdout','w') ;
$fps['screen'] = fopen('php://temp','w') ;
MultiHandlesWrite($fps,'This is test to write to differ multi handler in single function ');