Ankündigung

Einklappen
Keine Ankündigung bisher.

Bilder nachladen über eine PHP-Datei, sehr hoher TTFB

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Bilder nachladen über eine PHP-Datei, sehr hoher TTFB

    Hallo,

    ich habe eine media.php welche Bilddateien von verschiedenen Dateiservern lädt und dann mittels des richtigen PHP-headers und einem echo ausgibt.
    Tut und macht was es soll, tadellos.

    Wenn ich nun Bilder nachlade, z.B. eine Gallerie öffne, dann haut mir der Server unfassbare Wartezeiten um die Ohren. so dauert es manchmal 2 Sekunden und manchmal sag und schreibe 8 Sekunden.
    An dem was die PHP-Datei tut liegt es eigentlich nicht, ich kann egal welche Datei angefodert wird diese im separaten Tab öffnen und die Ladezeit liegt bei ~60ms.

    Bei vereinzelte Bilder während des Seitenaufbaus tritt es komischerweise nicht auf. Wird ein vereinzeltes Bild nachgeladen pendelt es so 60ms - 1Sekunde.
    Aber wie gesagt bei meinem Gallerie-Beispiel, werden 13 Bilder (thumbnails kleiner als 100Kib) nachgeladen sobald man eben diese öffnet.

    Ich vermute mal ich muss apache/ngnix hier entsprechend konfigurieren?


    Ich hoffe das mir einer weiter helfen kann, bin da echt ratlos und habe es gerade die letzten 2 Wochen alles umgebaut um auf diese media.php umzusteigen und so ist es echt untragbar


    LG: Paykoman

  • #2
    Ich tippe mal, dass die Ursache im PHP-Code liegt, der hier wieder mal geheim gehalten wird.

    Kommentar


    • #3
      Ja weil es zu komplex ist und vermutlich den Rahmen sprengen würde, btw. die get Parameter werden lediglich aufgeschlüsselt und dann mit file_get_contents(); das Bild vom Dateiserver geladen, bzw. es wird eine weitere php Datei die auf dem Dateiserver liegt angesprochen welche wenn nötig Thumbnails etc. erstellt (daher undurchsichtig und komplex).

      Aber wie gesagt ich kann jedes beliebiges Bild das "nachgeladen" wird auch manuell in einem neuen Tab ansehen hier ist eine Konstante Ladezeit von 60ms es liegt daher nicht am PHP-Code, würde mich schwer wundern.

      Aber gut ich mache mir nachher die Mühe und schreibe ein Log-file wo dann protokolliert wird wie lange das ganze dauert was die php Datei so ausführt und macht...
      Dann kann man das vergleichen.

      Kommentar


      • #4
        Naja, wenn du 13 Vollbilder lädst und Tumba erzeugst, dann dauert das sicher länger als 1s
        Pre-Coffee-Posts sind mit Vorsicht zu geniessen!

        Kommentar


        • #5
          Zitat von Paykoman Beitrag anzeigen
          Ja weil es zu komplex ist
          Dann vereinfache es nach und nach. Ab dem Zeitpunkt, wos dann plötzlich schneller geht, weißt du, was Schuld hat.

          Kommentar


          • #6
            Die Thumbnails und co werden nicht mit jedem Request erstellt, ich habe einen cache der regelmäßig geleert wird aber sofern das angeforderte Bild eben Vorhanden ist wird da nichts erstellt sondern direkt aus dem cache geladen.

            Das mir schon klar das je nachdem wie viel PHP da zu tun hat um so länger benötigt bis das Bild letztlich ausgeliefert wird.
            Da aber wie gesagt die on-the-fly erstellten Bilder gecached werden und die lange Antwortzeit dann natürlich auch auftreten müsste wenn ich die media.php einzend in einem Tab aufrufe.

            Denn ob ich die Datei direkt im Tab öffne oder über den src="" Attribute einbinde kann das nicht beeinflussen was die Datei macht und wie gesagt einzeln im Tab ist es zu 100% zuverlässig und es ist immer 40-60ms und zack das Bild ist zu sehen (ohne Ausnahme).

            Aber gut werde mich jetzt an der Log-File machen und mal gucken was dann dort heraus kommt und dann poste ich hier auch die media.php damit jeder sehen kann was wie wo gemessen wird =)

            Kommentar


            • #7
              Zitat von Paykoman Beitrag anzeigen
              Die Thumbnails und co werden nicht mit jedem Request erstellt, ich habe einen cache der regelmäßig geleert wird aber sofern das angeforderte Bild eben Vorhanden ist wird da nichts erstellt sondern direkt aus dem cache geladen.
              Wie gesagt, vereinfache es. Dann lass halt mal den Cache weg, wenn er das Ergebnis beeinflusst.

              Kommentar


              • #8
                So ich habe den Log mal gebastelt, gut aller menschlichen Logik zum Trotze, die über src-Tag brauchen eben tatsächlich länger warum weiß ich nicht.
                Wie man in der Logfile schön sieht wenn ich des manuell aufrufe und mit F5 zu spame (Browsercache ist aus, natürlich) dann funktioniert alles wie am Schnürchen (wie bereits erwähnt.

                Aber nun gut, da werde ich morgen wohl damit anfangen Dateinamen ins Log zu schreiben und dann auch auf dem Dateiserver ein Log erstellen damit ich nachvollziehen kann was der Dateiserver macht das es so lange dauert. Aber ich find es nach wie vor faszinierend das je nach Anforderungsquelle ein anderes Ergebnis kommt. Echt strange

                Wer mag kann sich durch die ganze class wuseln, aber oberhalb sind eigentlich nur die Empfänger die, die Get-parameter verarbeiten und den Request zum Dateiserver mehr oder weniger vorbereiten unten die letzten 3 Funktionen sind der finale Auswurf und da sind auch die Log Zeilen jetzt mit drine da kann man dann nach vollziehen wie die zeit gemessen wir.

                media.php
                PHP-Code:
                <?php
                $log 
                "Bild angefordert via ".((!isset($_GET['tab'])) ? 'Website     - ' 'eigenem Tab - ');
                $start microtime(true);
                define('adminRoute'false);

                /** FrameWork auto-settings - The System set the paths! No changes here! */
                $ds DIRECTORY_SEPARATOR;
                define('root'dirname(__FILE__).$ds); // contains real path to cms+

                /** apps config */
                $host str_replace('www.'''$_SERVER['HTTP_HOST']);
                $app json_decode(file_get_contents(root.'apps.cfg'), true);
                $app = (isset($app[$host])) ? $app[$host] : $app['default'];
                define('APP_FOLDER'$app[0]);
                define('APP_PATH'$app[0].$ds);
                define('APP_KEY'$app[1]);

                /** load config */
                require_once(root.APP_PATH.'config.php');
                define('fSrvUrl'$settings['defines']['fSrvUrl']);

                /** Database */
                require(dirname(__FILE__).'/fw/class/Database.php');
                $db = new Database($settings['db']['app']);
                $db->connect();

                /** load session */
                require(dirname(__FILE__).'/fw/class/session.php');
                new 
                session([$settings['sessHandler'], $settings['srcver'], $settings['csp'], $settings['cookie_domain']]);
                session::create();
                function 
                ageVerified(){
                    return ( isset(
                $_SESSION['member']) && in_array(5$_SESSION['groups'])) ? true false;
                }

                class 
                getMedia{
                    private 
                $imgTpl;
                    private 
                $defaultAR 18;
                    private 
                $profile = ['upic''ppic''bpic''ucov''pcov''bcov']; // prefixes of pofile pictures and covers

                    
                function __construct($imgTpl){
                        
                $this->imgTpl $imgTpl;

                        if( 
                method_exists($thisarray_keys($_GET)[0]) ){
                            
                $this->{array_keys($_GET)[0]}();
                        }else{
                            
                $this->ppic(); // get param like upic, ppic, bpic and for cover: ucov, pcov, bcov
                        
                }
                    }

                // acces to files (first get parameter on url call this functions)
                    
                private function ogp(){
                        
                $this->loadImg($_GET['ogp'], $_GET['id'], false'items/site-share.png');
                    }
                    private function 
                pic(){
                        if( 
                $_GET['srv'] !== 'null' && ctype_xdigit($_GET['pic']) && !is_numeric($_GET['pic']) ){
                            
                // an hex-converted picture, load it without proof access
                            // var_dump(hex2bin($_GET['pic'])); exit;
                            
                $pic explode('.'hex2bin($_GET['pic']));
                            
                $ext array_pop($pic);
                            
                $pic explode('-'$pic[0]);

                            
                // age restriction
                            // die pic-Funktion soll nicht validieren und einfach das angeforderte Bild zurück geben, wenn JS oder hintergrund Skripte der Datei eine "2" vorn angestellt haben soll das Bild unscharf dargestellt werden.
                            
                $ar = (substr($pic[0], 01) == '2') ? 18 0//  && !$this->fileAccess($pic[0]) fileAccess() return a flase if we need to bluerred, so set ar to 0 if we got a true
                            
                $pic[0] = ltrim($pic[0], '2');

                            
                $this->_pic(['id' => array_pop($pic), 'oid' => implode('-'$pic), 'ext' => $ext'srv' => intval($_GET['srv']), 'ar' => $ar], ($ar === 0)); // ar must be null the website need to add the 2 at beginning self
                        
                }else if( isset($_GET['nopic']) ){
                            
                $this->_nopic('nopic-'.$_GET['nopic'].'.jpg');
                        }else{
                            
                $this->_nopic('not-found.jpg');
                        }
                    }
                    private function 
                nopic(){
                        
                $this->_nopic('nopic-'.$_GET['nopic'].'.jpg');
                    }
                    private function 
                thumb(){
                        if( 
                $_GET['srv'] != 'null' && ctype_xdigit($_GET['thumb']) && !is_numeric($_GET['thumb']) ){
                            
                // var_dump(hex2bin($_GET['thumb'])); exit;
                            
                $pic explode('.'hex2bin($_GET['thumb']));
                            
                $ext array_pop($pic);
                            
                $pic explode('-'$pic[0]);
                            
                $file = ['id' => array_pop($pic), 'oid' => ltrim(implode('-'$pic), '2'), 'ext' => $ext'srv' => $_GET['srv'], 'ar' => (substr($pic[0], 01) == '2') ? 18 0];

                            
                $this->_thumbnail($file, ['w' => $_GET['w'], 'h' => $_GET['h']], ($file['ar'] === || !$this->fileAccess($file['oid']) ) ? true false);
                        }else if( isset(
                $_GET['nopic']) ){
                            
                $this->_nopic('nopic-'.$_GET['nopic'].'.jpg');
                        }else{
                            
                $this->_nopic('not-found.jpg');
                        }
                    }

                // custom function
                    // profile picture/cover
                    
                private function ppic(){
                        
                $type false;
                        foreach( 
                $this->profile as $t ){
                            if( isset(
                $_GET[$t]) ){
                                
                $type $t;
                                break;
                            }
                        }

                        if( 
                $type !== false ){
                            
                $pid $_GET[$type];
                            
                $this->loadImg($type.'-'.$pid1, (isset($_SESSION['member']) && $pid == $_SESSION['profile']['id']), 'nopic-'.$type.'.jpg'); // in_array($m[2], array_values($_SESSION['pids']))
                        
                }else{
                            
                $this->_nopic('nopic-'.$type.'.jpg');
                        }
                    }

                    
                // album cover need $_GET: ac = oid & fid = cover-file-ID & w = width and h = height of thumbnail
                    
                private function ac(){
                        global 
                $db;

                        
                $pic $db->select('* FROM <pf>media_pic WHERE oid = :oid AND id = :id LIMIT 1', [
                            
                ':oid' => strip_tags(htmlspecialchars($_GET['ac'])),
                            
                ':id' => intval($_GET['fid'])
                        ]);

                        if( 
                $pic !== false ){
                            
                $this->_thumbnail($pic, ['w' => $_GET['w'], 'h' => $_GET['h']], (isset($_SESSION['member']) && explode('-'$pic['oid'])[1] == $_SESSION['profile']['id']) ? true false);
                        }else{
                            
                $this->_nopic('nopic-cover.jpg');
                        }
                    }

                    
                // marketplace picture of article - only for browse-page (article listing)
                    
                private function mp(){
                        global 
                $db;

                        
                $pic $db->select('* FROM <pf>media_pic WHERE oid = :oid AND id = :id LIMIT 1', [
                            
                ':oid' => 'mp-'.intval($_GET['mp']).'-'.intval($_GET['aid']),
                            
                ':id' => intval($_GET['pid'])
                        ]);

                        if( 
                $pic !== false ){
                            
                $this->_thumbnail($pic, ['w' => 225'h' => 225], (isset($_SESSION['member']) && intval($_GET['mp']) == $_SESSION['member']['id']) ? true false);
                        }else{
                            
                $this->_nopic('nopic.jpg');
                        }
                    }

                // helper
                    
                private function fileAccess($oid){
                        
                // return true if we need to blur the media
                        // cp = community post, uf = user file (all unspecified uploads). The first number on file name must be userID or profileID.
                        
                return ( isset($_SESSION['member']) && !empty(preg_match('/(pic|mp|cp|uf)-([0-9]*)-/'$oid$m)) && (($m[1] != 'mp' && !in_array($m[2], array_values($_SESSION['pids'])) ) || ($m[1] == 'mp' && intval($m[2]) !== $_SESSION['member']['id'] )) );
                    }
                    private function 
                loadImg($oid$id$own$nopic){
                        global 
                $db;
                        
                $pic $db->select('* FROM <pf>media_pic WHERE oid = :oid AND id = :id LIMIT 1', [':oid' => strip_tags(htmlspecialchars($oid)), ':id' => intval($id)]);
                        
                // var_dump($pic); exit;

                        
                if( $pic !== false ){
                            
                $this->_pic($pic, (!is_null($own)) ? $own $this->fileAccess($pic['oid']));
                        }else{
                            
                $this->_nopic($nopic);
                        }
                    }

                // output pictures
                    
                private function _thumbnail($pic$size$own false){
                        global 
                $log$start;
                        
                $brakepoint microtime(true);
                        
                $log .= "ready to load thumb after ".number_format($brakepoint $start4',''')." sec -> ";
                        
                $img file_get_contents(str_replace('{id}'$pic['srv'], fSrvUrl).'/thumb.php?file='.$pic['oid'].'-'.$pic['id'].'&ext='.$pic['ext'].'&w='.$size['w'].'&h='.$size['w'].((!$own && $pic['ar'] > && !ageVerified() ) ? '&bl=1' '').((isset($_GET['re'])) ? '&force=true' ''));
                        
                $log .= "file loaded in ".number_format(microtime(true) - $brakepoint4',''')."sec - process in total: ".number_format(microtime(true) - $start4',''')."sec
                "
                ;
                        
                file_put_contents(root.'media.log'$logFILE_APPEND);

                        if( 
                $img != '' ){
                            
                header('Content-Type: image/'.$pic['ext']);
                            echo 
                $img;
                        }else if( isset(
                $_GET['nopic']) ){
                            
                $this->_nopic('nopic-'.$_GET['nopic'].'.jpg');
                        }else{
                            
                $this->_nopic('not-found.jpg');
                        }
                    }
                    private function 
                _pic($pic$own false){
                        global 
                $log$start;
                        
                $brakepoint microtime(true);
                        
                $log .= "ready to load pic   after ".number_format($brakepoint $start4',''')." sec -> ";
                        
                // var_dump(str_replace('{id}', $pic['srv'], fSrvUrl).'/get.php?file='.$pic['oid'].'-'.$pic['id'].'.'.$pic['ext'].'&ext='.$pic['ext'].((!$own && $pic['ar'] > 0 && !ageVerified() ) ? '&bl=1' : '')); exit;
                        
                $img file_get_contents(str_replace('{id}'$pic['srv'], fSrvUrl).'/get.php?file='.$pic['oid'].'-'.$pic['id'].'.'.$pic['ext'].'&ext='.$pic['ext'].((!$own && $pic['ar'] > && !ageVerified() ) ? '&bl=1' ''));
                        
                $log .= "file loaded in ".number_format(microtime(true) - $brakepoint4',''')."sec - process in total: ".number_format(microtime(true) - $start4',''')."sec
                "
                ;
                        
                file_put_contents(root.'media.log'$logFILE_APPEND);

                        if( 
                $img != '' ){
                            
                header('Content-Type: image/'.$pic['ext']);
                            echo 
                $img;
                        }else if( isset(
                $_GET['nopic']) ){
                            
                $this->_nopic('nopic-'.$_GET['nopic'].'.jpg');
                        }else{
                            
                $this->_nopic('not-found.jpg');
                        }
                    }
                    private function 
                _nopic($pic){
                        
                $img file_get_contents(root.APP_PATH.'tpl_r/'.$this->imgTpl.'/images/items/'.$pic);

                        switch( 
                pathinfo($picPATHINFO_EXTENSION) ){
                            case 
                "gif"$ctype="image/gif"; break;
                            case 
                "png"$ctype="image/png"; break;
                            case 
                "jpg"$ctype="image/jpeg"; break;
                            case 
                "svg"$ctype="image/svg+xml"; break;
                        }
                        
                header('Content-type: ' $ctype);
                        echo 
                $img;
                    }
                }
                new 
                getMedia($settings['noimgTpl']);


                // a download
                // header('Content-Type: application/octet-stream');
                // header('Content-Disposition: attachment; filename='.$_GET['saveas']);
                // readfile( 'file/'.$splitt_request[0] );
                Code:
                -- first load --
                Bild angefordert via Website     - ready to load pic   after 0,0019 sec -> file loaded in 0,2110sec - process in total: 0,2129sec
                Bild angefordert via Website     - ready to load pic   after 0,0072 sec -> file loaded in 0,2826sec - process in total: 0,2898sec
                Bild angefordert via Website     - ready to load thumb after 0,0017 sec -> file loaded in 0,0641sec - process in total: 0,0658sec
                Bild angefordert via Website     - ready to load thumb after 0,0014 sec -> file loaded in 0,0697sec - process in total: 0,0712sec
                Bild angefordert via Website     - ready to load thumb after 0,0015 sec -> file loaded in 1,3400sec - process in total: 1,3416sec
                Bild angefordert via Website     - ready to load thumb after 0,0177 sec -> file loaded in 0,3206sec - process in total: 0,3383sec
                Bild angefordert via Website     - ready to load thumb after 0,0241 sec -> file loaded in 0,3575sec - process in total: 0,3817sec
                Bild angefordert via Website     - ready to load thumb after 0,0174 sec -> file loaded in 0,3828sec - process in total: 0,4002sec
                Bild angefordert via Website     - ready to load thumb after 0,0228 sec -> file loaded in 0,4248sec - process in total: 0,4476sec
                Bild angefordert via Website     - ready to load thumb after 0,0017 sec -> file loaded in 0,0509sec - process in total: 0,0527sec
                Bild angefordert via Website     - ready to load thumb after 0,0012 sec -> file loaded in 0,0663sec - process in total: 0,0675sec
                Bild angefordert via Website     - ready to load thumb after 0,0016 sec -> file loaded in 0,0471sec - process in total: 0,0487sec
                Bild angefordert via Website     - ready to load thumb after 0,0015 sec -> file loaded in 2,4655sec - process in total: 2,4670sec
                Bild angefordert via Website     - ready to load thumb after 0,0214 sec -> file loaded in 1,3669sec - process in total: 1,3883sec
                Bild angefordert via Website     - ready to load thumb after 0,0221 sec -> file loaded in 1,4385sec - process in total: 1,4606sec
                Bild angefordert via Website     - ready to load thumb after 0,0012 sec -> file loaded in 1,0529sec - process in total: 1,0541sec
                --reload--
                Bild angefordert via Website     - ready to load pic   after 0,0019 sec -> file loaded in 0,0121sec - process in total: 0,0140sec
                Bild angefordert via Website     - ready to load pic   after 0,0020 sec -> file loaded in 0,0215sec - process in total: 0,0234sec
                Bild angefordert via Website     - ready to load thumb after 0,0023 sec -> file loaded in 0,0067sec - process in total: 0,0090sec
                Bild angefordert via Website     - ready to load thumb after 0,0019 sec -> file loaded in 0,0120sec - process in total: 0,0139sec
                Bild angefordert via Website     - ready to load thumb after 0,0010 sec -> file loaded in 0,0140sec - process in total: 0,0150sec
                Bild angefordert via Website     - ready to load thumb after 0,0014 sec -> file loaded in 1,1779sec - process in total: 1,1793sec
                Bild angefordert via Website     - ready to load thumb after 0,0010 sec -> file loaded in 1,1812sec - process in total: 1,1822sec
                Bild angefordert via Website     - ready to load thumb after 0,0019 sec -> file loaded in 1,1665sec - process in total: 1,1684sec
                Bild angefordert via Website     - ready to load thumb after 0,0010 sec -> file loaded in 1,1826sec - process in total: 1,1836sec
                Bild angefordert via Website     - ready to load thumb after 0,0017 sec -> file loaded in 1,1685sec - process in total: 1,1702sec
                Bild angefordert via Website     - ready to load thumb after 0,0010 sec -> file loaded in 1,1748sec - process in total: 1,1758sec
                Bild angefordert via Website     - ready to load thumb after 0,0010 sec -> file loaded in 1,1660sec - process in total: 1,1671sec
                Bild angefordert via Website     - ready to load thumb after 0,0097 sec -> file loaded in 0,1086sec - process in total: 0,1183sec
                Bild angefordert via Website     - ready to load thumb after 0,0019 sec -> file loaded in 0,0095sec - process in total: 0,0115sec
                Bild angefordert via Website     - ready to load thumb after 0,0012 sec -> file loaded in 0,0082sec - process in total: 0,0094sec
                Bild angefordert via Website     - ready to load thumb after 0,0015 sec -> file loaded in 0,0077sec - process in total: 0,0093sec
                -- aber hier habe ich mir ein Thumbnail von ben genommen und im Tab geöffnet --
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0076 sec -> file loaded in 0,0547sec - process in total: 0,0623sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0021 sec -> file loaded in 0,0078sec - process in total: 0,0099sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0018 sec -> file loaded in 0,0073sec - process in total: 0,0090sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0017 sec -> file loaded in 0,0068sec - process in total: 0,0085sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0017 sec -> file loaded in 0,0068sec - process in total: 0,0086sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0019 sec -> file loaded in 0,0072sec - process in total: 0,0091sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0022 sec -> file loaded in 0,0068sec - process in total: 0,0090sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0018 sec -> file loaded in 0,0065sec - process in total: 0,0082sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0029 sec -> file loaded in 0,0084sec - process in total: 0,0114sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0017 sec -> file loaded in 0,0078sec - process in total: 0,0094sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0021 sec -> file loaded in 0,0067sec - process in total: 0,0088sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0019 sec -> file loaded in 0,0067sec - process in total: 0,0086sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0017 sec -> file loaded in 0,0066sec - process in total: 0,0082sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0015 sec -> file loaded in 0,0063sec - process in total: 0,0078sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0014 sec -> file loaded in 0,0062sec - process in total: 0,0076sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0036 sec -> file loaded in 0,0066sec - process in total: 0,0102sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0020 sec -> file loaded in 0,0068sec - process in total: 0,0088sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0015 sec -> file loaded in 0,0062sec - process in total: 0,0077sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0016 sec -> file loaded in 0,0070sec - process in total: 0,0086sec
                Bild angefordert via eigenem Tab - ready to load thumb after 0,0015 sec -> file loaded in 0,0062sec - process in total: 0,0077sec

                Kommentar


                • #9
                  Ich sehe gerade, dass du auch eine Session verwendest. Dir muss halt auch bewusst sein, dass eine Session alle anderen Prozesse, die auf die selbe Session zugreifen möchten, blockiert. Dadurch können sich viele wartende Prozesse ansammeln, die den Webserver blockieren.

                  Wie bereits schon zweimal gesagt habe, würde ich empfehlen alles zu vereinfachen. Also auch mal Sessions weg lassen.

                  Im übrigens solltest du kein global Verwenden. Das macht auch noch Fehlerquellen schwerer auffindbar und hat bei OOP sowieso nichts verloren.

                  Und ein Konstruktor einer Klasse sollte keine Ausgaben machen. Ein Konstruktor ist, wie der Name schon sagt, nur dafür verantwortlich die Instanz zu konstruieren. Nicht mehr und nicht weniger.

                  Kommentar


                  • #10
                    hellbringer, danke fürs Feedback und auch die anderen Aufmerksamkeiten.
                    Nur kurz wegen der session, genau darum habe ich ja bevor die Dateiserver angesprochen werden eine Zwischenbillanz eingebaut und im log sieht man hier wunder bar das alles in wenigen ms abgehandelt ist.
                    Daran kann man dann eben sehen wie lange der Webserver beschäftigt ist bevor er überhaupt die Anfrage an den Dateiserver sendet und danach bekomme ich die exakte Antwortzeit und beide Zeiten addiert ergeben dann die gesamte Prozessdauer.


                    Nun habe ich auch beim Dateiserver den Log hinzugefügt und ja es bleibt leider etwas rätzelhaft
                    Ich mach alle Dateien mal kleiner damit man ggf. eine bessere Übersicht hat:

                    media.php
                    PHP-Code:
                    <?php
                    $start 
                    microtime(true);
                    $log "IMG: ".((!isset($_GET['tab'])) ? '[Website]' '    [Tab]');

                    class 
                    getMedia{
                        
                    /** mache dies und das und am Ende eine der Output-Funktionen ansprechen */

                    // output pictures
                        
                    private function _thumbnail($pic$size$own false){
                            global 
                    $log$start;
                            
                    $brakepoint microtime(true); // bis hier hin verstrichene Zeit ermitteln
                            
                    $log .= "[".$pic['oid'].'-'.$pic['id'].'.'.$pic['ext']."] ready to load thumb after ".number_format($brakepoint $start4',''')." sec -> ";

                            
                    $img file_get_contents(str_replace('{id}'$pic['srv'], fSrvUrl).'/thumb.php?file='.$pic['oid'].'-'.$pic['id'].'&ext='.$pic['ext'].'&w='.$size['w'].'&h='.$size['w'].((!$own && $pic['ar'] > && !ageVerified() ) ? '&bl=1' '').((isset($_GET['re'])) ? '&force=true' '')); // dateiserver die Datei anfordern

                            
                    $log .= "file loaded in ".number_format(microtime(true) - $brakepoint4',''')."sec - process in total: ".number_format(microtime(true) - $start4',''')."sec";// anforderungszeit und gesamt zeit
                            
                    file_put_contents(root.'media.log'$log."\n"FILE_APPEND);

                                
                    header('Content-Type: image/'.$pic['ext']);
                                echo 
                    $img;
                        }
                        private function 
                    _pic($pic$own false){
                            global 
                    $log$start;
                            
                    $brakepoint microtime(true); // bis hier hin verstrichene Zeit ermitteln
                            
                    $log .= "[".$pic['oid'].'-'.$pic['id'].'.'.$pic['ext']."] ready to load pic   after ".number_format($brakepoint $start4',''')." sec -> ";

                            
                    $img file_get_contents(str_replace('{id}'$pic['srv'], fSrvUrl).'/get.php?file='.$pic['oid'].'-'.$pic['id'].'.'.$pic['ext'].'&ext='.$pic['ext'].((!$own && $pic['ar'] > && !ageVerified() ) ? '&bl=1' '')); // dateiserver die Datei anfordern

                            
                    $log .= "file loaded in ".number_format(microtime(true) - $brakepoint4',''')."sec - process in total: ".number_format(microtime(true) - $start4',''')."sec"// anforderungszeit und gesamt zeit
                            
                    file_put_contents(root.'media.log'$log."\n"FILE_APPEND);

                                
                    header('Content-Type: image/'.$pic['ext']);
                                echo 
                    $img;
                        }
                    }
                    new 
                    getMedia($settings['noimgTpl']);
                    Dateiserve thumb.php
                    PHP-Code:
                    <?php
                    $start 
                    microtime(true);
                    $log "thumb  ".$_GET['file']." ";

                    // file datas
                    $orgName 'store/'.$_GET['file'].'.'.$_GET['ext'];
                    $thumbName 'thumb/'.((isset($_GET['bl']) ) ? '2' '').$_GET['file'].'_'.$_GET['w'].'-'.$_GET['h'].'.png';

                    if( 
                    $_GET['ext'] !== 'gif' ){
                        
                    // create/load thumbnail
                        
                    if( file_exists($thumbName) && !isset($_GET['force']) ){
                            echo 
                    file_get_contents($thumbName);
                            
                    $log .= "loaded from thumb in ".number_format(microtime(true) - $start4',''')."sec";
                        }else{
                            require_once(
                    'api/create.php');
                            
                    create::thumbnail();
                            
                    $log .= "thumb created in ".number_format(microtime(true) - $start4',''')."sec";
                        }

                    }

                    file_put_contents(dirname(__FILE__).'/media.log'$log."\n"FILE_APPEND);
                    Dann habe ich einmal die Gallerie geöffnet um alles zu erstellen damit beim zweiten Aufruf alles aus dem cache geladen werden kann und somit schnell von statten gehen sollte, Großteils wars tatsächlich flott es gab aber 3 Ausreißer (aber so ein Ergebnis kommt eher selten wie oben bereits beschrieben ist der Regelfall 1-2 Sekunden und länger).

                    Code:
                    media.log
                    IMG: [Website][ucov-30-1.jpg] ready to load pic   after 0,0013 sec -> file loaded in 0,0098sec - process in total: 0,0111sec
                    IMG: [Website][upic-30-1.jpg] ready to load pic   after 0,0046 sec -> file loaded in 0,0110sec - process in total: 0,0156sec
                    IMG: [Website][uf-30-1-4.jpg] ready to load thumb after 0,0018 sec -> file loaded in 0,0066sec - process in total: 0,0084sec
                    IMG: [Website][uf-30-1-1.jpg] ready to load thumb after 0,0015 sec -> file loaded in 0,0179sec - process in total: 0,0195sec
                    IMG: [Website][uf-30-1-3.jpg] ready to load thumb after 0,0013 sec -> file loaded in 0,0270sec - process in total: 0,0283sec
                    IMG: [Website][uf-30-1-4.jpg] ready to load thumb after 0,0030 sec -> file loaded in 0,0171sec - process in total: 0,0201sec
                    IMG: [Website][uf-30-1-2.jpg] ready to load thumb after 0,0011 sec -> file loaded in 0,0294sec - process in total: 0,0305sec
                    IMG: [Website][uf-30-1-6.jpg] ready to load thumb after 0,0014 sec -> file loaded in 0,0248sec - process in total: 0,0262sec
                    IMG: [Website][uf-30-1-7.jpg] ready to load thumb after 0,0009 sec -> file loaded in 0,0237sec - process in total: 0,0245sec
                    IMG: [Website][uf-30-1-8.jpg] ready to load thumb after 0,0010 sec -> file loaded in 0,0237sec - process in total: 0,0248sec
                    IMG: [Website][uf-30-1-13.jpg] ready to load thumb after 0,0012 sec -> file loaded in 0,0156sec - process in total: 0,0169sec
                    IMG: [Website][uf-30-1-11.jpg] ready to load thumb after 0,0010 sec -> file loaded in 0,0163sec - process in total: 0,0173sec
                    IMG: [Website][uf-30-1-12.jpg] ready to load thumb after 0,0027 sec -> file loaded in 0,0148sec - process in total: 0,0175sec
                    IMG: [Website][uf-30-1-4.jpg] ready to load pic   after 0,0011 sec -> file loaded in 0,0068sec - process in total: 0,0079sec
                    IMG: [Website][uf-30-1-5.jpg] ready to load thumb after 0,0014 sec -> file loaded in 1,0301sec - process in total: 1,0315sec
                    IMG: [Website][uf-30-1-9.jpg] ready to load thumb after 0,0016 sec -> file loaded in 0,0065sec - process in total: 0,0081sec
                    IMG: [Website][uf-30-1-10.jpg] ready to load thumb after 0,0015 sec -> file loaded in 1,0117sec - process in total: 1,0132sec
                    
                    
                    Datrei-server log
                    get    ucov-30-1.jpg loaded from thumb in 0,0001sec
                    get    upic-30-1.jpg loaded from thumb in 0,0000sec
                    thumb  uf-30-1-4 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-1 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-3 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-4 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-2 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-6 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-7 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-8 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-13 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-11 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-12 loaded from thumb in 0,0001sec
                    get    uf-30-1-4.jpg loaded from thumb in 0,0001sec
                    thumb  uf-30-1-5 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-9 loaded from thumb in 0,0001sec
                    thumb  uf-30-1-10 loaded from thumb in 0,0001sec
                    So nun kann man hier sehen das der Dateiserver die Dateien nicht erstellen musste und rubbel die Katz die existierenden Dateien via "echo file_get_contents($thumbName);" ausgegeben hat und das auch schön blitz schnell.
                    Der Webserver hat 2 Dateien wo die Antwort 1 Sekunde betragen hat, hier ist ja schon die Frage warum 2 Dateien 1 Sekundebrauchten wenn doch alle so schnell per echo ausgegeben wurden?
                    Und zu guter letzt habe ich im Frontend 3 Ausreißer (siehe Bild).

                    Es bleibt also die Frage woher diese Flatulenzen kommen?

                    Kommentar


                    • #11
                      Ach vllt. auch mal ganz interessant.. auch wenn der Dateiserver die thumbnails erstellen muss, sind wir weit weit entfernt von auch nur 1 Sekunde. Es muss also am Übertragungsweg liegen.

                      Code:
                      thumb  uf-30-1-8 thumb created in 0,0839sec
                      thumb  uf-30-1-7 thumb created in 0,0552sec
                      thumb  uf-30-1-3 thumb created in 0,1023sec
                      thumb  uf-30-1-10 thumb created in 0,0467sec
                      thumb  uf-30-1-12 thumb created in 0,1397sec
                      thumb  uf-30-1-13 thumb created in 0,1555sec
                      get    uf-30-1-4.jpg thumb created in 0,3219sec
                      get    ucov-30-1.jpg thumb created in 0,2408sec
                      get    upic-30-1.jpg thumb created in 0,0137sec
                      thumb  uf-30-1-4 thumb created in 0,0554sec
                      thumb  uf-30-1-1 thumb created in 0,0396sec
                      thumb  uf-30-1-3 thumb created in 0,2035sec
                      thumb  uf-30-1-9 thumb created in 0,0371sec
                      thumb  uf-30-1-8 thumb created in 0,0395sec
                      thumb  uf-30-1-4 loaded from thumb in 0,0001sec
                      thumb  uf-30-1-7 thumb created in 0,0462sec
                      thumb  uf-30-1-12 thumb created in 0,0536sec
                      thumb  uf-30-1-13 thumb created in 0,0718sec
                      thumb  uf-30-1-5 thumb created in 0,1071sec
                      thumb  uf-30-1-10 thumb created in 0,1595sec
                      thumb  uf-30-1-6 thumb created in 0,1365sec
                      get    uf-30-1-4.jpg thumb created in 0,4429sec
                      thumb  uf-30-1-11 thumb created in 0,0480sec
                      thumb  uf-30-1-2 thumb created in 0,0600sec
                      Und zu erwähnen ist das die zeit gemessen wird nach dem create::thumb(); ausgeführt wurde, das beinhaltet das erstellen und dann auch wieder die Ausgabe die dann eben vom Webserver erhalten werden soll.

                      Kommentar


                      • #12
                        $img = file_get_contents(str_replace('{id}', $pic['srv'], fSrvUrl).'/thumb.php?file='.$pic['oid'].'-'.$pic['id'].'&ext='.$pic['ext'].'&w='.$size['w'].'&h='.$size['w'].((!$own && $pic['ar'] > 0 && !ageVerified() ) ? '&bl=1' : '').((isset($_GET['re'])) ? '&force=true' : '')); // dateiserver die Datei anfordern
                        $img = file_get_contents(str_replace('{id}', $pic['srv'], fSrvUrl).'/get.php?file='.$pic['oid'].'-'.$pic['id'].'.'.$pic['ext'].'&ext='.$pic['ext'].((!$own && $pic['ar'] > 0 && !ageVerified() ) ? '&bl=1' : '')); // dateiserver die Datei anfordern
                        Du erzeugst neue Web Requests, dh. das geht nochmal durch den Webserver... warum?

                        Anhand von "thumb loaded" siehst du, das vorhandene Dateien in Bruchteilen von Sekunden geladen werden. Was du vorne misst ist die Latenz eines internen HTTP Requests, der halt völlig unnötig ist... Die Dateien existieren lokal, also lad sie einfach direkt.
                        Über 90% aller Gewaltverbrechen passieren innerhalb von 24 Stunden nach dem Konsum von Brot.

                        Kommentar

                        Lädt...
                        X