Well, since you asked.... :-)
It's not safe because any number of users can end up trying to update it at the same time, leading to non-deterministic results.
To be safe/accurate, the file needs to be locked. As an additional bonus, the following code will do all the updating with a single file open, so the lost efficiency due to the lock will be at least partly offset be eliminating the overhead of the two (!) exec's:
function get_next_counter_value($Counterfile )
{
$fp = fopen($Counterfile, "r+"); // + is key here: update mode lets us write too
flock($fp, 2 );
$num = fgets($fp,10) + 1; // allow more the 99999 hits
rewind($fp);
fwrite( $fp, printf("%d", $num ));
flock($fp, 3 );
return $num;
}