Mostra notizie nelle discussioni
  • Avatar
    Scritto da
    Non Autenticato
    il 2010-07-19 15:07:00.0 alle 2010-07-19 15:07:00.0
    Il contatore di insulae.net
    mi sta facendo dannare.

    Il file del conto ora è

    1964|/index.php|20100719|20070118
    26|/credits.php|20100719|20100630
    24|/contact.php|20100719|20100630
    4|-|20100501|20080221
    55|/index.php|20100719|20100713
    1|/contact.write.send.php|20100717|20100717

    e come si vede si sono formate DUE righe per index.php, così sul sito mostra un conto di 55 invece che 1964+55.

    Non riesco a capire perché. Arrabbiato

    Il sorgente del contatore è

    <?

    // Adapted from MPCount 1.02 Sascha Blansjaar

    $url = $_SERVER['PHP_SELF'];
    if (!isset($url)) $url = "-";

    // setting the same $url for all pages results in a same count for the whole site

    $today = date("Ymd");
    $written = FALSE;

    $msg = '';

    // Uses the daita() function, which must be defined in the including script

    // Uses $_GET['c'] received calling url?c=no

    if (file_exists($mpcountfile)) {

        $temparray = file($mpcountfile);

        for ($index = 0; $index < count($temparray); $index++) {

            $entry = explode("|", $temparray[$index]);

            if (!strcmp($entry[1], $url)) {

                if ($_GET['c'] != 'no') $entry[0]++;
                $entry[2] = $today;
                $tempentry = $entry;
                $temparray[$index] = implode($entry, "|");
                $fp = fopen($mpcountfile, "w");
                if (flock($fp, 2)) {
                    for ($j = 0; $j < count($temparray); $j++) {
                        fputs($fp, $temparray[$j]);
                    }
                } else {
                    $msg = 'ERROR: flock write failure';
                }

                if (flock($fp, 3)) {
                    fclose($fp);
                } else {
                    $msg = 'ERROR: flock release failure';
                }

                $count = $tempentry[0];
                $since = str_replace("\n", '', $tempentry[3]);
                $since = daita($since);

                $written = TRUE;

            }

        }

        if ($written == FALSE) {
            $hits = "1";
            $entry = "$hits|$url|$today|$today\n";
            $fp = fopen($mpcountfile, "a");
            if (flock($fp, 2)) {
                fputs($fp, $entry, 1024);
            } else {
                $msg = 'ERROR: flock write failure';
            }
            if (flock($fp, 3)) {
                fclose($fp);
            } else {
                $msg = 'ERROR: flock release failure';
            }
            $count = $hits;
            $since = daita($today);
        }

    } else {

        $fp = fopen($mpcountfile, "w");
        if (!$fp) {
            $msg = 'CNT error';
        } else {
            fclose ($fp);
            $msg = 'Count register created.';
        }

    }

    ?>

    La citata funzione daita() serve solo a trasformare la data in formato leggibile.

    Succede spesso che si formino doppie righe, e non riesco a immaginare quale evento le provoca.

    Arrabbiato Arrabbiato Arrabbiato
    • Avatar
      ☺
      Scritto da
      il 2010-07-19 16:17:00.0 alle 2010-07-19 16:17:00.0
      Trollate totali: 42885
      Re: Il contatore di insulae.net

      - Scritto da:

      > Succede spesso che si formino doppie righe, e non
      > riesco a immaginare quale evento le
      > provoca.

      Thread safe Newbie, inesperto ?
      `"la realta' non e' cosi' terrificante come vogliono farti credere" - Giambo ` - Wakko che cita Giambo
      • Avatar
        Scritto da
        Non Autenticato
        il 2010-07-19 16:23:00.0 alle 2010-07-19 16:23:00.0
        Re: Il contatore di insulae.net
        > > Succede spesso che si formino doppie righe, e
        > non
        > > riesco a immaginare quale evento le
        > > provoca.
        >
        > Thread safe Newbie, inesperto ?

        Ho pensato a una race condition, ma flock dovrebbe evitarlo e poi non riesco a immaginare che tipo di situazione porta lo script a scrivere un'altra riga per la stessa pagina.

        Se avessi idea delle condizioni che producono l'errore, potrebbe venirmi in mente come fare.

        Oltretutto capita ogni tanto ma raramente, e quindi è difficile da studiare.
    • Avatar
      ☺
      Scritto da
      avvelentani
      Cubicolario
      il 2010-07-19 18:29:00.0 alle 2010-07-19 18:29:00.0
      Trollate totali: 18184
      Re: Il contatore di insulae.net
      - Scritto da:
      > mi sta facendo dannare.
      >
      > Il file del conto ora è
      >
      > 1964|/index.php|20100719|20070118
      > 26|/credits.php|20100719|20100630
      > 24|/contact.php|20100719|20100630
      > 4|-|20100501|20080221
      > 55|/index.php|20100719|20100713
      > 1|/contact.write.send.php|20100717|20100717
      >
      > e come si vede si sono formate DUE righe per
      > index.php, così sul sito mostra un conto di 55
      > invece che
      > 1964+55.
      >
      > Non riesco a capire perché. Arrabbiato
      >
      > Il sorgente del contatore è
      >
      > <?
      >
      > // Adapted from MPCount 1.02 Sascha Blansjaar
      >
      > $url = $_SERVER['PHP_SELF'];
      > if (!isset($url)) $url = "-";
      >
      > // setting the same $url for all pages results in
      > a same count for the whole
      > site
      >
      > $today = date("Ymd");
      > $written = FALSE;
      >
      > $msg = '';
      >
      > // Uses the daita() function, which must be
      > defined in the including
      > script
      >
      > // Uses $_GET['c'] received calling url?c=no
      >
      > if (file_exists($mpcountfile)) {
      >
      >     $temparray = file($mpcountfile);
      >
      >     for ($index = 0; $index < count($temparray);
      > $index++)
      > {
      >
      >         $entry = explode("|", $temparray[$index]);
      >
      >         if (!strcmp($entry[1], $url)) {
      >
      >             if ($_GET['c'] != 'no') $entry[0]++;
      >             $entry[2] = $today;
      >             $tempentry = $entry;
      >             $temparray[$index] = implode($entry,
      > "|");
      >             $fp = fopen($mpcountfile, "w");
      >             if (flock($fp, 2)) {
      >                 for ($j = 0; $j <
      > count($temparray); $j++)
      > {
      >                     fputs($fp, $temparray[$j]);
      >                 }
      >             } else {
      >                 $msg = 'ERROR: flock write
      > failure';
      >             }
      >
      >             if (flock($fp, 3)) {
      >                 fclose($fp);
      >             } else {
      >                 $msg = 'ERROR: flock release
      > failure';
      >             }
      >
      >             $count = $tempentry[0];
      >             $since = str_replace("\n", '',
      > $tempentry[3]);
      >             $since = daita($since);
      >
      >             $written = TRUE;
      >
      >         }
      >
      >     }
      >
      >     if ($written == FALSE) {
      >         $hits = "1";
      >         $entry = "$hits|$url|$today|$today\n";
      >         $fp = fopen($mpcountfile, "a");
      >         if (flock($fp, 2)) {
      >             fputs($fp, $entry, 1024);
      >         } else {
      >             $msg = 'ERROR: flock write failure';
      >         }
      >         if (flock($fp, 3)) {
      >             fclose($fp);
      >         } else {
      >             $msg = 'ERROR: flock release failure';
      >         }
      >         $count = $hits;
      >         $since = daita($today);
      >     }
      >
      > } else {
      >
      >     $fp = fopen($mpcountfile, "w");
      >     if (!$fp) {
      >         $msg = 'CNT error';
      >     } else {
      >         fclose ($fp);
      >         $msg = 'Count register created.';
      >     }
      >
      > }
      >
      > ?>
      >
      > La citata funzione daita() serve solo a
      > trasformare la data in formato
      > leggibile.
      >
      > Succede spesso che si formino doppie righe, e non
      > riesco a immaginare quale evento le
      > provoca.
      >
      > Arrabbiato Arrabbiato Arrabbiato

      mi viene da vomitare.
      I think happiness is love
      - Vladimir Putin
    • Avatar
      Scritto da
      Non Autenticato
      il 2010-07-19 18:31:00.0 alle 2010-07-19 18:31:00.0
      Re: Il contatore di insulae.net

      - Scritto da:
      > mi sta facendo dannare.
      >
      > Il file del conto ora è
      >
      > 1964|/index.php|20100719|20070118
      > 26|/credits.php|20100719|20100630
      > 24|/contact.php|20100719|20100630
      > 4|-|20100501|20080221
      > 55|/index.php|20100719|20100713
      > 1|/contact.write.send.php|20100717|20100717
      >
      > e come si vede si sono formate DUE righe per
      > index.php, così sul sito mostra un conto di 55
      > invece che
      > 1964+55.
      >
      > Non riesco a capire perché. Arrabbiato
      >
      > Il sorgente del contatore è
      >
      > <?
      >
      > // Adapted from MPCount 1.02 Sascha Blansjaar
      >
      > $url = $_SERVER['PHP_SELF'];
      > if (!isset($url)) $url = "-";
      >
      > // setting the same $url for all pages results in
      > a same count for the whole
      > site
      >
      > $today = date("Ymd");
      > $written = FALSE;
      >
      > $msg = '';
      >
      > // Uses the daita() function, which must be
      > defined in the including
      > script
      >
      > // Uses $_GET['c'] received calling url?c=no
      >
      > if (file_exists($mpcountfile)) {
      >
      >     $temparray = file($mpcountfile);
      >
      >     for ($index = 0; $index < count($temparray);
      > $index++)
      > {
      >
      >         $entry = explode("|", $temparray[$index]);
      >
      >         if (!strcmp($entry[1], $url)) {
      >
      >             if ($_GET['c'] != 'no') $entry[0]++;
      >             $entry[2] = $today;
      >             $tempentry = $entry;
      >             $temparray[$index] = implode($entry,
      > "|");
      >             $fp = fopen($mpcountfile, "w");
      >             if (flock($fp, 2)) {
      >                 for ($j = 0; $j <
      > count($temparray); $j++)
      > {
      >                     fputs($fp, $temparray[$j]);
      >                 }
      >             } else {
      >                 $msg = 'ERROR: flock write
      > failure';
      >             }
      >
      >             if (flock($fp, 3)) {
      >                 fclose($fp);
      >             } else {
      >                 $msg = 'ERROR: flock release
      > failure';
      >             }
      >
      >             $count = $tempentry[0];
      >             $since = str_replace("\n", '',
      > $tempentry[3]);
      >             $since = daita($since);
      >
      >             $written = TRUE;
      >
      >         }
      >
      >     }
      >
      >     if ($written == FALSE) {
      >         $hits = "1";
      >         $entry = "$hits|$url|$today|$today\n";
      >         $fp = fopen($mpcountfile, "a");
      >         if (flock($fp, 2)) {
      >             fputs($fp, $entry, 1024);
      >         } else {
      >             $msg = 'ERROR: flock write failure';
      >         }
      >         if (flock($fp, 3)) {
      >             fclose($fp);
      >         } else {
      >             $msg = 'ERROR: flock release failure';
      >         }
      >         $count = $hits;
      >         $since = daita($today);
      >     }
      >
      > } else {
      >
      >     $fp = fopen($mpcountfile, "w");
      >     if (!$fp) {
      >         $msg = 'CNT error';
      >     } else {
      >         fclose ($fp);
      >         $msg = 'Count register created.';
      >     }
      >
      > }
      >
      > ?>
      >
      > La citata funzione daita() serve solo a
      > trasformare la data in formato
      > leggibile.
      >
      > Succede spesso che si formino doppie righe, e non
      > riesco a immaginare quale evento le
      > provoca.
      >
      > Arrabbiato Arrabbiato Arrabbiato

      ma file($mpcountfile) è automaticamente protetto da un lock? mi sa di no

      comunque anche con quel lock ti perderesti ugualmente degli aggiornamenti sul file, dovresti coprire tutto (lettura e riscrittura) con un write lock

      IMHO SE&O (e comunque non so un cazzo su queste cose)
<softv>

Pagina generata in 53 millisecondi

Utenti attivi: 11 nell'ultimo minuto, 19 negli ultimi cinque minuti, 37 negli ultimi 15 minuti