Array als PHP-snipped in Datei schreiben und lesen – SELFHTML-Forum Forum als Ergänzung zum SELFHTML-Wiki und zur Dokumentation SELFHTML https://forum.selfhtml.org/self Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 11:19:36 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791405#m1791405 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791405#m1791405 <p>Moin,</p> <p>für die Termintypen von Veanstaltungsdaten erzeuge ich ein 2-dimensionales Array, das sich monatelang nicht ändert. Also möchte ich es nicht bei jedem Programmlauf per SQL und PHP neu erzeugen (0.04900s), sondern einmalig in eine Datei schreiben und die Datei als PHP-Code lesen (0.00000s).</p> <p>Obwohl <a href="https://www.php.net/manual/de/function.file-put-contents.php" rel="nofollow noopener noreferrer">file_put_contents</a> ein array zulässt, kann ich es von Datei mit file_get_contents nicht wieder herstellen:</p> <pre><code class="block language-php"><span class="token keyword">echo</span> <span class="token string double-quoted-string">"<pre class=nodisplay>arr_termintypen:\n\n"</span><span class="token punctuation">;</span> <span class="token function">var_dump</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"</pre>\n"</span><span class="token punctuation">;</span> <span class="token function">file_put_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.php"</span><span class="token punctuation">,</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$test</span> <span class="token operator">=</span> <span class="token function">file_get_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.php"</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"<pre class=nodisplay>test:\n\n"</span><span class="token punctuation">;</span> <span class="token function">var_dump</span><span class="token punctuation">(</span> <span class="token variable">$test</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"</pre>\n"</span><span class="token punctuation">;</span> </code></pre> <p>Ergebnis:</p> <pre><code class="block language-txt"><pre class=nodisplay>arr_termintypen: array(44) { [24]=> array(12) { ["TYP"]=> string(2) "24" ["anzahl_termine"]=> string(1) "0" ["typgruppe_id"]=> string(1) "1" ["color"]=> string(7) "#f2004c" ["sort"]=> string(7) "bil_fue" ["typ_beschreibung"]=> string(0) "" ["gruppe_de"]=> string(7) "Bildung" ["name_de"]=> string(23) "Führung, Bildungsreise" ["gruppe_en"]=> string(9) "Education" ["name_en"]=> string(32) "Guided tour, Educational journey" ["gruppe_nl"]=> string(9) "Onderwijs" ["name_nl"]=> string(28) "Rondleiding, educatieve reis" } [47]=> array(12) { ... } } </pre> <pre class=nodisplay>test: string(220) "ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray" </pre> </code></pre> <p>Was mache ich falsch?</p> <p>fragt Linuchs</p> Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 11:27:16 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791406#m1791406 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791406#m1791406 <p>Hallo Linuchs,</p> <blockquote> <p>Obwohl <a href="https://www.php.net/manual/de/function.file-put-contents.php" rel="nofollow noopener noreferrer">file_put_contents</a> ein array zulässt, kann ich es von Datei mit file_get_contents nicht wieder herstellen:</p> </blockquote> <p>Du musst das Handbuch schon genau lesen: der zweite Parameter darf ein <em>eindimensionales</em> Array sein, die Elemente des Arrays werden dann aneinander gehängt und in die Datei geschrieben.</p> <p>Du suchst <a href="https://www.php.net/function.var-export" rel="nofollow noopener noreferrer">var_export()</a> (true als 2. Parameter nicht vergessen), damit kannst du die Variable als PHP-Code in die Datei schreiben.</p> <p>Gruß<br> Tobias</p> Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 11:33:16 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791407#m1791407 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791407#m1791407 <p>Hello,</p> <p>dir könnten die Funktionen rund um <a href="https://www.php.net/manual/en/function.parse-ini-file" rel="nofollow noopener noreferrer">parse_ini_file()</a> helfen.</p> <p>Ich habe dafür auch mal eine Umkehrfunktion geschrieben. Vielleicht ist die noch im Wiki vorhanden...</p> <p>siehe <a href="https://wiki.selfhtml.org/wiki/PHP/Tutorials/INI-Datei_aus_einem_Array_erstellen" rel="nofollow noopener noreferrer">hier</a></p> <p>Glück Auf<br> Tom vom Berg</p> <div class="signature">-- <br> Es gibt nichts Gutes, außer man tut es!<br> Das Leben selbst ist der Sinn. </div> Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 11:53:02 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791410#m1791410 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791410#m1791410 <p>Tach!</p> <blockquote> <p>Obwohl <a href="https://www.php.net/manual/de/function.file-put-contents.php" rel="nofollow noopener noreferrer">file_put_contents</a> ein array zulässt, kann ich es von Datei mit file_get_contents nicht wieder herstellen:</p> </blockquote> <p>Dass man ein Array angeben kann, ist wohl <code>file()</code> geschuldet, denn das liefert ein Array, mit je einer Zeile pro Element. Und auch nur ein solches wird von <code>file_put_contents()</code> geschrieben. Alles andere wird zu String konvertiert. Wenn man ein Array zu String konvertiert kommt der String "Array" raus, und der eigentliche Inhalt geht verloren. Das passiert bei dir mit den Elementen ab der zweiten Ebene. Wenn du Datenstrukturen verlustfrei in eine Textdatei schreiben und wieder lesen möchtest, kannst du sie <a href="https://www.php.net/manual/en/function.serialize" rel="nofollow noopener noreferrer">serialisieren</a>. Damit sind sie ein einzelner langer String. Für das Lesen gibt es <a href="https://www.php.net/manual/en/function.unserialize.php" rel="nofollow noopener noreferrer">eine Umkehrfunktion</a>.</p> <p>dedlfix.</p> Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 13:50:43 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791417#m1791417 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791417#m1791417 <p><code>printf('Hallo %s!', ['Du', 'ihr', 'Welt', 'zusammen'][rand(0, 3)]);</code></p> <blockquote> <p>für die Termintypen von Veanstaltungsdaten erzeuge ich ein 2-dimensionales Array, das sich monatelang nicht ändert. Also möchte ich es nicht bei jedem Programmlauf per SQL und PHP neu erzeugen (0.04900s), sondern einmalig in eine Datei schreiben und die Datei als PHP-Code lesen (0.00000s).</p> <p>Obwohl <a href="https://www.php.net/manual/de/function.file-put-contents.php" rel="nofollow noopener noreferrer">file_put_contents</a> ein array zulässt, kann ich es von Datei mit file_get_contents nicht wieder herstellen:</p> </blockquote> <p>Arraywerte speichert und liest man am einfachsten (MNSHO) als <a href="https://www.php.net/manual/en/ref.json.php" rel="nofollow noopener noreferrer">JSON</a>. Kann man dann mit file_(put|get)_contents problemlos schreiben/lesen</p> <p>/K</p> <div class="signature">-- <br> Klingonen sind doof. Sie rufen ständig nach einem Kaplan und wollen nach dem Tod in Styropor® sein. </div> Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 11:46:16 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791409#m1791409 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791409#m1791409 <p>Hallo tk,</p> <p>was es nicht alles gibt - den kannte ich noch gar nicht.</p> <p>Aber wenn, dann <code>var_export($array, true)</code>, damit ein String rauskommt und das Ergebnis nicht direkt ausgegeben wird. Und wenn man es als PHP Code verwenden will, dann so:</p> <pre><code class="block language-php">file_put_contents("cache/data.php", "<?php return " . var_export($array, true) . ";"); $test = include "cache/data.php"; </code></pre> <p>Den cache-Ordner sollte man dann übrigens außerhalb des Webroot ablegen, den müssen User nicht abrufen können.</p> <p>Wie wär's übrigens mit serialize/unserialize? Der Output ist ein gutes Stück kleiner, und man muss nicht PHP Code von "irgendwo" ausführen. Ich würde dafür als Extension dat verwenden und nicht php, denn ausführbarer PHP Code ist es nicht.</p> <pre><code class="block language-php"><span class="token function">file_put_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.dat"</span><span class="token punctuation">,</span> <span class="token function">serialize</span><span class="token punctuation">(</span><span class="token variable">$arr_termintypen</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$test</span> <span class="token operator">=</span> <span class="token function">unserialize</span><span class="token punctuation">(</span><span class="token function">file_get_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.dat"</span> <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </code></pre> <p>Es mag allerdings beim Einlesen langsamer sein, weil es kein PHP Code ist und deshalb nicht im Opcode-Cache landet. Ob man es messen kann? Dafür bräuchte man vermutlich Testdaten im Umfang von 1 MB...</p> <p><em>Rolf</em></p> <div class="signature">-- <br> sumpsi - posui - obstruxi </div> DANKE Mon, 06 Sep 21 12:32:29 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791413#m1791413 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791413#m1791413 <p>Hallo Tobias,</p> <p>danke, funktioniert:</p> <pre><code class="block language-php"><span class="token function">file_put_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.php"</span><span class="token punctuation">,</span> <span class="token function">var_export</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span><span class="token punctuation">,</span> <span class="token constant boolean">TRUE</span> <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">unset</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$arr_termintypen</span> <span class="token operator">=</span> <span class="token function">file_get_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.php"</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> </code></pre> <p>Gruß Linuchs</p> Array als PHP-snipped in Datei schreiben und lesen Mon, 06 Sep 21 12:02:49 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791411#m1791411 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791411#m1791411 <p>Hallo Rolf,</p> <p>so, Testdaten erzeugt. Meine data.php ist 1,7MB groß, 4000 Wiederholungen der Row, die Linuchs oben als Beispiel gegeben hat.</p> <p>50 Includes dauern 1,2 Sekunden oder 25ms pro Vorgang.</p> <p>50 unserializes dauern 0,33 Sekunden oder 7ms pro Vorgang.</p> <p>Das war allerdings mein Kommandozeilen-PHP 8.02 unter Windows; es mag auf einem Webserver mit besserem Opcode-Cache besser für die include-Variante aussehen.</p> <p>Es hängt aber auch am PHP, mit PHP 5.6 waren es 29ms für die include-Version und 39ms für die unserialize-Version!</p> <p>Mit PHP 7.4 sind es 21ms für die include-Version und 5ms für die unserialize-Version.</p> <p>Sehr merkwürdig, dass PHP 8 beim unserialize langsamer geworden ist, ich muss wohl mal die PHP.INI Dateien der Versionen vergleichen...</p> <p><em>Rolf</em></p> <div class="signature">-- <br> sumpsi - posui - obstruxi </div> ... doch nicht Mon, 06 Sep 21 13:38:07 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791416#m1791416 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791416#m1791416 <p>weiß nicht, warum das geklappt hat, jetzt nicht mehr:</p> <pre><code class="block language-php"><span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_array</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"arr_termintypen IS array<br>"</span><span class="token punctuation">;</span> <span class="token keyword">else</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"arr_termintypen KEIN array<br>"</span><span class="token punctuation">;</span> <span class="token keyword">unset</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$arr_termintypen</span> <span class="token operator">=</span> <span class="token function">file_get_contents</span><span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.php"</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_array</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"arr_termintypen IS array<br>"</span><span class="token punctuation">;</span> <span class="token keyword">else</span> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"arr_termintypen KEIN array<br>"</span><span class="token punctuation">;</span> </code></pre> <p>arr_termintypen IS array</p> <p>arr_termintypen KEIN array</p> <p>In der Datei steht</p> <pre><code class="block language-php"><span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token number">24</span> <span class="token operator">=></span> <span class="token keyword">array</span> <span class="token punctuation">(</span> <span class="token string single-quoted-string">'TYP'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'24'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'anzahl_termine'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'0'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'letzter_tag'</span> <span class="token operator">=></span> <span class="token constant">NULL</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'typgruppe_id'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'1'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'color'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'#f2004c'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'sort'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'bil_fue'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'typ_beschreibung'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">''</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'gruppe_de'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Bildung'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name_de'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Führung, Bildungsreise'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'gruppe_en'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Education'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name_en'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Guided tour, Educational journey'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'gruppe_nl'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Onderwijs'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'name_nl'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Rondleiding, educatieve reis'</span><span class="token punctuation">,</span> <span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">47</span> <span class="token operator">=></span> <span class="token operator">...</span> </code></pre> 2. Lösungsversuch Mon, 06 Sep 21 14:54:32 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791421#m1791421 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791421#m1791421 <p>Hallo Tobias und Rolf,</p> <p>so funktioniert es jetzt:</p> <p>erstelleArrayTermintypen.php:</p> <pre><code class="block language-php">// zusätzlich zum internen Array file_put_contents( "cache/arr_termintypen.php", "<span class="token php language-php"><span class="token delimiter important"><?</span>php\n<span class="token string double-quoted-string">" . '<span class="token interpolation"><span class="token variable">$arr_termintypen</span></span> = ' . var_export( <span class="token interpolation"><span class="token variable">$arr_termintypen</span></span>, TRUE ) . "</span>\n<span class="token delimiter important">?></span></span>" ); </code></pre> <p>Hauptprogramm:</p> <pre><code class="block language-php"><span class="token keyword">include_once</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"erstelleArrayTermintypen.php"</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// alle TYPen in de, en, nl</span> <span class="token keyword">unset</span><span class="token punctuation">(</span> <span class="token variable">$arr_termintypen</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// erstellte cache-Datei als PHP-array einbinden</span> <span class="token keyword">include_once</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"cache/arr_termintypen.php"</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// array</span> </code></pre> <p>Linuchs</p> ... doch nicht Mon, 06 Sep 21 13:52:50 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791418#m1791418 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791418#m1791418 <p>Hallo Linuchs,</p> <blockquote> <p>$arr_termintypen = file_get_contents( "cache/arr_termintypen.php" );</p> </blockquote> <p>file_get_contents ist die falsche Funktion um den Code zu lesen und als PHP-Array zur Verfügung zu haben. Du musst eine richtige PHP-Datei draus machen (also <?php und return vor das eigentliche Array) und include/require verwenden, siehe <a href="https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791409#m1791409" rel="noopener noreferrer">Antwort von Rolf</a>.</p> <p>Gruß<br> Tobias</p> ... doch nicht Mon, 06 Sep 21 14:08:45 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791419#m1791419 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791419#m1791419 <p>Hallo tk,</p> <p>ja, file_get_contents holt den Dateiinhalt als String, führt ihn aber nicht aus. Dafür müsste man einen eval("return " + $filecontent + ";") nachschalten (Ahhh! Nicht hauen!!!)</p> <p>Wenn man ausführbaren Code erzeugen will, dann "<?php return " vor den var_export und ein ";" dahinter. Das Ergebnis lässt sich dann includen.</p> <p>Ob das schneller oder langsamer ist als serialize/unserialize muss man dann auf dem konkreten System messen. Der Opcode-Cache dürfte hier eine wesentliche Rolle spielen.</p> <p>json_encode/json_decode statt serialize/unserialize geht auch, es produziert in diesem Fall hier sogar eine deutlich kleinere Datei. Aber in meinem Test braucht unserialize 6 ms für 4000 Zeilen und json_decode 15 ms (im Vergleich zu den 21.5ms für include). Und man muss aufpassen, json_decode mit <code>true</code> als 2. Parameter aufzurufen, damit man Arrays bekommt und nicht std_class Objekte.</p> <p><em>Rolf</em></p> <div class="signature">-- <br> sumpsi - posui - obstruxi </div> 2. Lösungsversuch Mon, 06 Sep 21 15:13:00 Z https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791425#m1791425 https://forum.selfhtml.org/self/2021/sep/06/array-als-php-snipped-in-datei-schreiben-und-lesen/1791425#m1791425 <p>Hallo Linuchs,</p> <p>nein, tu das nicht. Fixiere nicht den Namen der Variablen im include, das ist eine unnötige Abhängigkeit. Je weniger Koppelungen du hast, desto besser. Mach es deshalb so wie von mir gezeigt. Einen return ins Include und dann</p> <p><code>$arr_termintypen = include "cache/arr_termintypen.php";</code></p> <p>Keinen include_once - du includest ja keine Funktionen. Vielleicht MÖCHSTEST Du die Termintypen ja an 2 Stellen einlesen. Und auch keinen require. Denn hinter dem Einlesen sollte dies stehen:</p> <pre><code class="block language-php"><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$arr_termintypen</span> <span class="token operator">===</span> <span class="token constant boolean">FALSE</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token variable">$arr_termintypen</span> <span class="token operator">=</span> <span class="token function">loadTerminTypen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// aus der Datenbank</span> <span class="token function">file_put_contents</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"cache/arr_termintypen.php"</span><span class="token punctuation">,</span> <span class="token operator">...</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p>Dann brauchst Du nur den Cache zu löschen und der nächste Abruf erzeugt die Datei neu. Die Warning, die der include auf eine fehlende Datei schreibt, landet sicherlich nur bei Dir im Log und nicht im Browser, gelle?</p> <p>Hast Du mal die Laufzeit von unserialize auf deinem Server mit der von include verglichen?</p> <p><em>Rolf</em></p> <div class="signature">-- <br> sumpsi - posui - obstruxi </div>