I have a website where people submit content that is then inserted into a collective image. My code works, but I found one issue so far:
If 2 people try to write at the same time (both let’s say, submitted at the same time), this causes the output file to become 0KB, another words, it’s just an empty file.
I’m writing using an output buffer, GD2 and file_put_contents like so:
ob_start();
imagejpeg($map);
file_put_contents(MAP, ob_get_contents(), FILE_BINARY);
ob_end_clean();
What I’m wondering is what is the best way to go about solving this issue?
Thanks!
file_put_contents(MAP, ob_get_contents(), LOCK_EX)