[-] Fixes a race condition

Fixes a race condition leading to file coruption and PHP crashes when
writing the cache index file.

Handles concurrency properly by using a temporary file and an atomic
rename() instead of file_put_contents(), which is not atomic, on a
file which is potentially accessed by many processes at the same time
Merge pull request #407 from zecrazytux/fixracecondition

[-] Fixes a race condition