Advertisement:

Settings.php repeatedly gets emptied

Aloittaja Dario, elokuu 08, 2011, 02:18:58 IP

« edellinen - seuraava »

Dario

In 1.1.11, any idea why my Settings.php periodically ends up empty, crashing my forum? I fixed that file a few weeks ago, and now it's empty again. I haven't been changing anything, anywhere, and there are no other admins.

Thanks!

Illori

it is a server issue that causes it to be wiped out, try to chmod the file 444 and that should stop this from happening. this issue should be fixed in 2.0 if you want to try to upgrade.

tinoest

There is a way around this in SMF 1.1.x by making the following changes.

In /Settings.php, find

$db_last_error = 0;

Replace it with

// timestamp of last database error detected

include($boarddir . '/LastError.php');

// despite our best efforts, was this file emptied out?

if (!isset($db_last_error)) {
updateLastError(0);  // just give it a 0 value
$db_last_error = 0;
}


Create a new file named /LastError.php. It should be in the same directory (folder) as Settings.php.
<?php
$db_last_error 
0;
?>


Add a new function to /Sources/admin.php to update just the LastError.php file, rather than the entire Settings.php file.

This new code is inserted after the end of the updateSettingsFile() function (closing }).

// Avoid calling updateSettingsFile for $db_last_error. If there's one error,

function updateLastError($time) {
  global $boarddir;

  // Blank out the file - done to fix an oddity with some servers.
  $fp = @fopen($boarddir . '/LastError.php', 'w');

  // Is it even writable, though?
  if ($fp)  {
    fclose ($fp);
    $fp = fopen($boarddir . '/LastError.php', 'r+');
    fwrite($fp, "<?php\n");
    fwrite(
$fp, '$db_last_error = ' . $time . ";\n");
    fwrite(
$fp, '?' . ">\n"); // to prevent premature closing of PHP code
    fclose(
$fp);
  }
}


In /Sources/Errors.php, at approximately line 195, change the code to not rewrite the whole Settings.php file, but just the LastError.php file. Find updateSettingsFile(array('db_last_error' => time()));
and replace it with

updateLastError(time());

Do the same thing in /Sources/Subs-Auth.php, at approximately line 364. Find updateSettingsFile(array('db_last_error' => time()));
and replace it with

updateLastError(time());

Illori


Dario

#4
Lainaus käyttäjältä: Illori - elokuu 08, 2011, 02:23:02 IP
it is a server issue that causes it to be wiped out, try to chmod the file 444 and that should stop this from happening. this issue should be fixed in 2.0 if you want to try to upgrade.
Thanks for the help.
When I set it to 0444 via FTP, the change doesn't stick, for some reason. It goes back to 0644. (owner can read/write) I'm using FireFTP (Firefox addon), btw, if that makes any difference. (it shows the "0444" instead of "444", like I see in Dreamweaver) From what I can tell, my main app, Expression Web 4, doesn't allow permission changes (even though it's connecting via FTP, and not Front Page Extensions). Changing via Dreamweaver doesn't stick either.

Lainaus käyttäjältä: tinoest - elokuu 08, 2011, 02:42:15 IP
(code)
Thanks, I applied that.

Illori

you could also try using a real ftp client that would allow the permissions to be changed.

tinoest

Lainaus käyttäjältä: Illori - elokuu 08, 2011, 03:01:43 IP
would be nice to give credit where credit is due http://www.catskilltech.com/freeSW/SMF/fixes1.1/#settings

I had copied the above to a text file on my computer. (So had no record where it was from ) But you are right, the original author should take the credit. I was just posting trying to help.

MrPhil

Yes, I take credit  ;D . Making it read-only (444) is probably the quickest and easiest way, although I do give the code to handle it gracefully.

Thanks, Illori, for pointing out the source. BTW, it's usually not a matter of "a real FTP client" -- many hosts ignore remote file operations such as a chmod coming from an FTP client. And it's not solely a "server issue", either. Frequent database errors may well be, but SMF has a whopping big bug in it that leads to Settings.php being emptied out.

Advertisement: