Re: File concurrent file access
| From: | Jonathan Tapicer | Date: | Fri, 22 Jul 2011 14:10:04 +0000 |
| Subject: | Re: File concurrent file access | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314159@lists.php.net to get a copy of this message | ||
On Fri, Jul 22, 2011 at 10:44 AM, Florian Lemaitre
<florian.lemaitre@evolutioncom.eu> wrote:
> Hi !
>
> I'm developing my new website and I'm worried about concurrent file access.
> In fact, I want to suppress a maximum database interactions so I keep
> information in files with faster I/O than databases.
> But I'm worried by the fact that an error can occur when someone try to
> access a file being edited by a cron task.
>
> Does PHP do all the stuff itself or is there something to do about it ?
>
> PS: I only use file_get_contents, file_put_contentsand unlink on files.
>
> Best regards.
> Florian
>
With file_put_contents you send a flag to lock the file and avoid
concurrency problems, eg:
file_put_contents('/some/file', 'data', FILE_APPEND | LOCK_EX);
Regards,
Jonathan