Finish script in background // Skript im Hintergrund beenden

Alles, was PHP betrifft, kann hier besprochen werden.

Finish script in background // Skript im Hintergrund beenden

Postby noob2k12 » 25. April 2012 13:06

I use following function to track my users with Piwik. The server that i am running doesn't support the fastcgi_finish_request() - function so i am looking for another way to solve this. The request to Piwik takes about 300 milliseconds that i want to save. (its annoying to me to see "Page is loading..." but output has finished so far). Anyone out there that has an idea or a solution for this?

Ich nutze folgende Funktion um die Statistiken mit Piwik zu erfassen. Mein Server unterstützt leider die Funktion fastcgi_finish_request(); nicht, so dass ich nach einer anderen Möglichkeit suche. Die Anfrage benötigt blöderweise ~300ms, diese würde ich gern einsparen. Kann einer weiterhelfen?

Thx.

Code: Select all
<?php
   function shutdown() {
      global $PAGE, $IP, $NO_STATS;

      // Piwik
      if (($IP != "127.0.0.1") && (!$NO_STATS)) {
         /* if available*/
         if (function_exists("fastcgi_finish_request")) {
            /* send EOF to client so we stop loading the page and finish the request in the background */
            fastcgi_finish_request();
         }

         // finish script in background
         ignore_user_abort(true);

         // not more than 5 seconds for finishing piwik
         set_time_limit(5);

         /* takes ~300ms */
         require_once("/var/www/webXX/html/piwik/libs/PiwikTracker/PiwikTracker.php");
         PiwikTracker::$URL = "http://piwik.XX.de";
         $t = new PiwikTracker($idSite = 1, "http://piwik.XX.de/");
         $t->doTrackPageView("$PAGE");
      }
   }

   register_shutdown_function("shutdown");
?>
noob2k12
 
Posts: 1
Joined: 25. April 2012 12:56
XAMPP Version: 1.8.3-3
Operating System: Win7 x64

Return to PHP

Who is online

Users browsing this forum: No registered users and 0 guests