I tried to write a simple php file like this (and it worked):
<?php
echo("OK");
my question is:
Is it safe to write a php file without the "?>" at the end ?
Yes, it's documented that the closing tag at the end is optional.
In fact, it's better if you don't use it because if you do then sometimes extra whitespace at the end of your source ends up in the output when you don't want it to.
If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.
It is recommended not to use end tag when PHP file contains only PHP code.
If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.