Re: file_set_contents() do several times?

From: Date: Mon, 20 Jul 2009 08:48:15 +0000
Subject: Re: file_set_contents() do several times?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-295602@lists.php.net to get a copy of this message
David Otton napsal(a):
2009/7/20 Martin Zvarík <mzvarik@gmail.com>:
<?php $i = 0; do { $i++; $r = file_put_contents('file.txt', 'content'); } while($r === false && $i < 3); if ($r === false) die('error'); ?> Makes sense? or is it enough to do it just once?
Assuming 'content' changes, and this is the cut-down example... $r = file_put_contents('file.txt', 'content', FILE_APPEND); There's a small overhead in opening/closing the file three times instead of one, but I doubt that's going to be an issue for you.
I am not appending anything, just ensuring that it will be written (and giving it max. 3 tryes). === Martin Scotta replied: In my experience file_put_contents never fails, except about file permissions, but this is not the case. --- Thanks for your replies. Martin

« previous php.general (#295602) next »