strace -e trace=open, read, close, connect -p <pid>
$str='text :pattern1 text :pattern2 text :pattern3';
$array1=array_reverse(array('/:pattern1/', '/:pattern2/', '/:pattern3/'));
$array2= array_reverse(array(':pattern2', ':pattern3', 'foo'));
echo preg_replace($array1, $array2, $str);