Sessions sort strange .. or rather don't!

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

Sessions sort strange .. or rather don't!

Post by jazcyk »

se Image

I seems that this happens certain days - other days session logs are sorted. Today is 1st of month. Any idea? Conversion from UNIX_TIMESTAMP issue?
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

this is really strange. I'll take a look at it.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

problem persists

Post by jazcyk »

After update to 1.5.7 problems persists. And it did not help either that date changed ... :shock:

Do w simply have too many files/dates for the sorting algorithm? There are around 175 logfiles on the server.
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

I couldn't reproduce this yet but I'm still working on that problem.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

I rewrote the method that reads the session dates. It's checked into the 1.6 branch for testing and when everything works as it should I'll backport it into 1.5.8.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

here too

Post by jazcyk »

I have been researhing too.
I believe it is this code in /admin/stat.main.php:

Code: Select all

<?php
	$dir = opendir(PMF_ROOT_DIR."/data");
	while ($dat = readdir($dir)) {
		if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
			print "<option value=\"".FileToDate($dat)."\"";
			if (date("d.m.Y", FileToDate($dat)) == strftime("%d.%m.%Y", time())) {
				print " selected=\"selected\"";
				}
			print ">";
			print date("d.m.Y", FileToDate($dat));
			print "</option>\n";
			}
		}
	closedir($dir);
?>
It looks like function readdir() does not read files in the order that you would expect. Docs at php.net say
readdir()Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

Now we moved to another server last week. Files have been copied! Actually with the upgrade procedure that I use, I copy every time I upgrade! But you would experience the same in situations where a backup has been restored. You cannot expect the OS the copy files in the order that files were created!

I think it is a VERY POOR solution to use the file system create time as an index. Indexed data should in a database! Or the filenames should be read into an array and sorted. But why spend time with coding something that every database engine can already handle without the need for a single line of code ?!

I repeat my request to have the option to have session logs in the database!
Last edited by jazcyk on Fri Mar 03, 2006 8:45 am, edited 1 time in total.
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

I can post the new code here with the time sorting.

Logging into a database will break a database on a shared webhosting account... phpMyFAQ 1.0 did that and some users had very big problems with MySQL load.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

I know

Post by jazcyk »

Logging into a database will break a database on a shared webhosting account
I know that! That was why I asked for an option! But if you sort the file names, that will work too!

Let me see your code man! :)
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

here it is:

Code: Select all

	$dir = opendir(PMF_ROOT_DIR."/data");
    $trackingDates = array();
    
	while (false !== ($dat = readdir($dir))) {
		if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
			$trackingDates[] = filemtime('../data/' . $dat);
		}
	}
    
	closedir($dir);
?>
        <label class="left"><?php print $PMF_LANG["ad_stat_browse"]; ?>:</label>
		<select name="day" size="1">
<?php
    foreach ($trackingDates as $trackingDate) {
        printf('<option value="%s"', date("Y-m-d", $trackingDate));
        if (date("Y-m-d", $trackingDate) == strftime('%Y-%m-%d', time())) {
			print ' selected="selected"';
		}
		print '>';
		print date('Y-m-d', $trackingDate);
		print "</option>\n";
    }
?>
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

hehe

Post by jazcyk »

it now displays only '2006-03-02's
... but lots of them! :D

is it correct htat it should replace to code piece that I quoted?
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

yes, replace your code. I used this PHP function: http://www.php.net/manual/en/function.filemtime.php

What date have your files?

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

file dates are ...

Post by jazcyk »

yesterdays date (all of them), as files were copied yesterday.

I think you should read the FILENAMES into the array and sort! you will then have to generate 'YYYYMMDD' from 'trackingDDMMYYYY' first.

This solution you give here won't work with copied or restored files! Only the FILENAMES give the information. FILESYSTEM does not!
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

okay, please change the line

Code: Select all

$trackingDates[] = filemtime('../data/' . $dat);
with

Code: Select all

$trackingDates[] = FileToDate($dat);
and it should work.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

nope!

Post by jazcyk »

now dates are different, but they are not sorted as they should!

Check for yourself:
http://webyog.com/faq/admin/index.php

UID: thorsten
PW: phpmyfaq

you have 'view log' privilege only so I believe it is no risk to publish it here and keep it for some hours or days!

code module complete:

Code: Select all

<?php
   $dir = opendir(PMF_ROOT_DIR."/data");
    $trackingDates = array();

   while (false !== ($dat = readdir($dir))) {
      if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
         $trackingDates[] = FileToDate($dat);
      }
   }

   closedir($dir);
?>
        <label class="left"><?php print $PMF_LANG["ad_stat_browse"]; ?>:</label>
      <select name="day" size="1">
<?php
    foreach ($trackingDates as $trackingDate) {
        printf('<option value="%s"', date("Y-m-d", $trackingDate));
        if (date("Y-m-d", $trackingDate) == strftime('%Y-%m-%d', time())) {
         print ' selected="selected"';
      }
      print '>';
      print date('Y-m-d', $trackingDate);
      print "</option>\n";
    }
?>
Last edited by jazcyk on Fri Mar 03, 2006 9:46 am, edited 1 time in total.
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

I believe you because I'm stupid. :-)

I forgot the sorting!!! :-(

You can delete my account in your FAQ...

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply