Re: SV: problem with 1.4.0
| From: | Monte Ohrt | Date: | Wed, 09 May 2001 13:48:56 +0000 |
| Subject: | Re: SV: problem with 1.4.0 | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-707@lists.php.net to get a copy of this message | ||
This was a fix for windows that we had got from someone, which still
doesn't seem to work under win98 :( It looks like the file should get
truncated (ftruncate) each time it is written, but since that part is
now commented out, the file gets appended. If you look at the user
comments submitted for flock() on php.net, you'll see where this code
must have come from. Can anyone see why we need 'a' and ftruncate()?
Here is another solution that _should_ work (please test it), although
it will not do an exclusive lock on windows platforms that support it.
Can someone tell me the value of PHP_OS on windows 98? Maybe we can
pinpoint this.
function _write_file($filename, $contents, $create_dirs = false)
{
if ($create_dirs)
$this->_create_dir_structure(dirname($filename));
if (!($fd = fopen($filename, 'w'))) {
$this->_trigger_error_msg("problem writing '$filename.'");
return false;
}
if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd,
LOCK_EX)) ) {
fwrite( $fd, $contents );
fclose($fd);
chmod($filename,0644);
}
return true;
}
Tomas Sanchez Romani wrote:
>
> Hi!
>
> Problem might be solved, but it feels strange that no-one reacted to this
> before and that I (a PHP-intermediate-programmer fixed it. Ok the thing that
> works for me is to change the 'a' enclosed in -*[]*- to a 'w':
>
> /*======================================================================*\
> Function: _write_file()
> Purpose: write out a file
> \*======================================================================*/
> [...]
> if (!($fd = fopen($filename, -*['a']*-))) {
> -------------------------------------^^^^^^^^^-------------------
> $this->_trigger_error_msg("problem writing '$filename.'");
> return false;
> }
> // uncommented according to previuos advice by Monte
> // if (flock($fd, LOCK_EX) && ftruncate($fd, 0))
>
> fwrite( $fd, $contents );
> fclose($fd);
> chmod($filename,0644);
> // }
>
> return true;
> }
>
> Hope this helps someone with the same problem.
>
> a&l, tomas
>
> -----Ursprungligt meddelande-----
> Från: Tomas Sanchez Romani [mailto:tomas@altern.org]
> Skickat: den 9 maj 2001 11:28
> Till: Smarty List
> Ämne: [smarty] problem with 1.4.0
>
> Hi!
>
> I'm testing the example that comes bundled with smarty 1.4.0 and I'm having
> some trouble, first there was no output (fixed according to previous tip
> about smarty 1.4.0 and win32).
>
> Now everything was fine. Then I decided to change the standard dir-names to
> 'tpl' (templates) 'ctpl' (templates_c) and 'conf' (configs).
> There where no
> problems with 'tpl' and 'ctpl' but suddenly the configs where not found.
> Changed it back to 'configs' and they where fine again, but the final output
> now came out ten (10) times after each-other.
>
> Deleted the compiled templates and now it works fine. but for each reload of
> the document the new compiled template seems to append to the old, instead
> of replacing it.
>
> where did it go wrong?
>
> tomas
>
> ---
> You are currently subscribed to smarty as: tomas@altern.org
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
>
> ---
> You are currently subscribed to smarty as: monte@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/