<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lemmingzshadow.net &#187; PHP - lemmingzshadow.net - a webdevel&#039;s weblog</title>
	<atom:link href="http://lemmingzshadow.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://lemmingzshadow.net</link>
	<description>a webdevel&#039;s weblog</description>
	<lastBuildDate>Fri, 27 Apr 2012 20:35:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Performante PHP Projekte &#8211; Teil 1</title>
		<link>http://lemmingzshadow.net/449/performante-php-projekte-teil-1/</link>
		<comments>http://lemmingzshadow.net/449/performante-php-projekte-teil-1/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 20:35:31 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XCache]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=449</guid>
		<description><![CDATA[Immer mal wieder höre oder lese ich, dass man mit PHP keine performaten Webprojekte umsetzen könne. Satt aber nun einen weiteren PHP vs. Sprache-X Artikel zu verfassen habe ich mir überlegt stattdessen ein paar Tipps zu geben wie man meiner Meinung nach die Performance von PHP-Projekten optimieren kann. Da dies ein sehr umfangreiches Thema ist [...]]]></description>
			<content:encoded><![CDATA[<p>Immer mal wieder höre oder lese ich, dass man mit PHP keine performaten Webprojekte umsetzen könne. Satt aber nun einen weiteren PHP vs. Sprache-X Artikel zu verfassen habe ich mir überlegt stattdessen ein paar Tipps zu geben wie man meiner Meinung nach die Performance von PHP-Projekten optimieren kann. Da dies ein sehr umfangreiches Thema ist werde ich das Ganze in mehrere Artikel aufteilen. Anfangen werde ich in diesem ersten Beitrag mit ein paar Tipps zum Webserver.</p>
<p><strong>Lighttpd mit PHP-FPM</strong></p>
<p>Die meisten Root- oder V-Server werden in der Standard-Konfiguration ganz ohne Webserver oder mit Apache2 ausgeliefert. Mein Tipp hier: Alternativen testen! <a href="http://www.lighttpd.net/">Lighttpd </a>oder <a href="http://nginx.org/">Nginx</a> sind in vielen Fällen schneller und benötigen weniger Ressourcen. Jeder Webserver hat seine Vor- und Nachteile, es kann also nicht schaden die Alternativen einmal zu testen. Ich persönlich verwende schon seit längerem Lighttpd und bin sehr zufrieden damit. Die Konfiguration der verschieden Webserver sollte Dank zahlreicher Tutorials die im Netz verfügbar sind kein Problem darstellen.<br />
Desweiteren empfehle ich dringen statt des &#8220;üblichen&#8221; PHP-Moduls (mod_php) <a href="http://php-fpm.org/">PHP-FPM</a> zu verwenden.<span id="more-449"></span> Zusammen mit Lighttpd oder Nginx schafft ein Server so nicht selten wesentlich mehr Requests/Sec abzuarbeiten. Darüber hinaus bietet PHP-FPM einige sehr nützliche Features wie z.b. das Anlegen verschiedener Pools. Damit ist es möglich verschiedenen PHP-Prozesse mit verschiedenen Benutzern zu starten. Das bringt Sicherheits-Vorteile mit sich und lässt Schreibrechte-Probleme der Vergangenheit angehören. Zum Thema Lighttpd und PHP-FPM habe ich hier auch schon andere Beiträge <a href="http://lemmingzshadow.net/tag/lighttpd/">verfasst</a>.</p>
<p><strong>Opcode Caching mit XCache</strong></p>
<p><a href="http://lemmingzshadow.net/files/2012/04/xcache_admin.jpg" rel="facebox" rel="attachment wp-att-456"><img src="http://lemmingzshadow.net/files/2012/04/xcache_admin-150x150.jpg" alt="" title="xcache_admin" width="150" height="150" class="alignleft size-thumbnail wp-image-456" /></a>Da PHP keinen eigenen Opcode-Cache mit sich bringt fehlt dieser häufig auf Webserver. Ein Opcode oder <a href="http://de.wikipedia.org/wiki/PHP#Bytecode-Caching">Bytecode-Cache</a> sorgt dafür, dass PHP-Scripte nicht bei jedem Aufruf neu in Bytecode übersetzt werden müssen. Besonders bei vielen gleichzeitigen Anfragen an den Webserver kann ein solcher Cache die CPU-Last erheblich verringern. Neben dem Zend-Optimizer, eAccelerator und APC gibt es hier noch meinen persönlichen Favoriten <a href="http://xcache.lighttpd.net/">XCache</a>. Installation und Konfiguration sollten keine Probleme bereiten, da es für quasi jede Linux-Distribution bereits fertige Pakete gibt.<br />
Hinweisen möchte ich jedoch noch auf das <a href="http://xcache.lighttpd.net/wiki/InstallAdministration">XCache-Admin Feature</a> denn hier kann man gut sehen ob und wie gut der Opcode-Cache tatsächlich arbeitet. Die obere &#8220;Total&#8221; Zeile zeigt an wie viele der Requests aus dem Cache (hits) ausgeliefert werden konnten und wie viele nicht (misses). Ausserdem kann man sehen wie viel der zur Verfügung stehen Speichers aktuell benutzt wird. Sollte der Wert der Misses im Verhältnis zu den Hits sehr hoch sein, ist es ggf. sinnvoll XCache etwas mehr Speicher zu Verfügung zu stellen.</p>
<p><strong>Requests begrenzen &#8211; mod_evasive und mod_status</strong></p>
<p><a href="http://lemmingzshadow.net/files/2012/04/mod_status.jpg" rel="facebox" rel="attachment wp-att-450"><img src="http://lemmingzshadow.net/files/2012/04/mod_status-150x150.jpg" alt="" title="mod_status" width="150" height="150" class="alignleft size-thumbnail wp-image-450" /></a>Über Sinn oder Unsinn von Modulen wie <a href="http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModEvasive">mod_evasive</a> kann man sich selbstverständlich streiten und mir ist klar, dass keines dieser Module einem richtigen DDoS Angriff entgegenwirken kann, das liegt in der Natur der Sachen. Dennoch halte ich den Einsatz für sinnvoll, denn vielen &#8220;Script-Kiddy&#8221;-, Spam-, Brutforce- und sonstigen Attacken kann man damit einen Riegel vorschieben. Mod_evasive mach im Prinzip nichts weiter als die Requets pro IP auf den Webserver zu limitieren. Eine gute Übersicht über die Requests die Lighttp aktuell verabeitet liefert das Modul <a href="http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModStatus">mod_status</a>.</p>
<p><strong>Lasttest</strong><br />
Nachdem man nun alle (oder einen Teil) dieser Optimierungen vorgenommen hat. Sollte man seinen Webserver mit einem simplen Lasttest durchführen um zu sehen ob der Webserver wirklich durchhält wenn er ein paar parallele Requests abzuarbeiten hat. Tools für diese Aufgabe sind zum Beispiel <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">Apache Benchmark</a> oder <a href="http://www.loadui.org/">LoadUI</a>. Am besten startet man mit einigen wenigen Anfragen pro Sekunde und schaut auf der Konsole des Server wie sich da auf die Last auswirkt. Da man bei solchen Lasttests in der Regel nur von einer IP aus testet kann man hier auch direkt prüfen ob mod_evasive korrekt funktioniert. Ist das der Falls sollte man die Anfragen pro Sekunde im Lasttest-Tools quasi beliebig nach oben schrauben können ohne das die Serverlast merklich steigt. Wie viele Requests/Sec ein Server verträgt hängt natürlich start von der Hardware und dem aufgerufenen Script ab.<br />
Neben den Requests pro Sekunde sollte man auch noch darauf achten ob alle Anfragen nach einer bestimmten Zeit wieder geschlossen werden. Hierzu kann an einen Blick auf die mod_status Weboberfläche werden. Normalerweise sollten allen Verbindungen nach einer kurzen Zeit wieder geschlossen werden. Wenn Verbindungen für eine sehr lange Zeit offen bleiben oder gar nicht geschlossen werden, sollten die entsprechenden Parameter in der Konfiguration noch einmal überprüft werden.</p>
<p>Ich hoffe ich konnte in diesem kurzen Anriss zum Thema Webserver-Konfiguration auf die häufigsten Performance-Bremsen eingehen und ein paar nützliche Tipps geben. Anregungen natürlich wie immer hin den Kommentaren.</p>
<p>Im zweiten Teil der &#8220;Performance-Reihe&#8221; wird es dann um Datenbank-Abfragen gehen, bzw. darum wie man hier optimieren kann.</p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/449/performante-php-projekte-teil-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Websocket powered Twitterwall &#8211; Projektrelaunch</title>
		<link>http://lemmingzshadow.net/441/websocket-powered-twitterwall-projektrelaunch/</link>
		<comments>http://lemmingzshadow.net/441/websocket-powered-twitterwall-projektrelaunch/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 14:17:57 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Jitt]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[projekt]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=441</guid>
		<description><![CDATA[Endlich ist es soweit: Ich habe eine Projekt live geschaltet welches den von mir weiterentwickelten Websocket-Server produktiv nutzt. Ich habe mein altes Twitterwall-Projekt JITT von Grund auf neu entwickelt und eine erste Beta-Version steht nun unter jitt.li bereit. Das Projekt bietet Twitterwalls in Echtzeit. Dazu werden Tweets aus der Twitter Streaming-API direkt per Websocket-Server an [...]]]></description>
			<content:encoded><![CDATA[<p>Endlich ist es soweit: Ich habe eine Projekt live geschaltet welches den von mir weiterentwickelten <a href="https://github.com/lemmingzshadow/php-websocket">Websocket-Server</a> produktiv nutzt. Ich habe mein altes Twitterwall-Projekt JITT von Grund auf neu entwickelt und eine erste Beta-Version steht nun unter <a href="http://jitt.li">jitt.li</a> bereit.</p>
<p>Das Projekt bietet Twitterwalls in Echtzeit. Dazu werden Tweets aus der Twitter Streaming-API direkt per Websocket-Server an den Browser weitergeleitet. Ausserdem dient das Projekt natürlich auch dazu die Stabilität des Websocket-Servers im Live-Betrieb zu testen und weiter zu optimieren.<br />
Falls ihr in Zukunft also mal eine Twitterwall für ein Event o.Ä. braucht behaltet <a href="http://jitt.li">jitt.li</a> im Hinterkopf. <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/441/websocket-powered-twitterwall-projektrelaunch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Websocket Server/Client nach Draft hybi-10</title>
		<link>http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/</link>
		<comments>http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 12:16:26 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[featured post]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=386</guid>
		<description><![CDATA[Vor ein paar Tagen habe ich ja schon einen Websocket-Client hier veröffentlich, welcher Draft hybi-00 unterstützt. Kurz danach veröffentlichte google jedoch eine neue Version von Chrome. In Chrome 14 hat google nun den Websocket-Draft hybi-10 implementiert und dort hat sich vieles grundlegend geändert. Neben einem neuen Handshake werden auch die Datenframes komplett neu codiert. Ich [...]]]></description>
			<content:encoded><![CDATA[<p>Vor ein paar Tagen habe ich ja schon einen Websocket-Client hier veröffentlich, welcher Draft hybi-00 unterstützt. Kurz danach veröffentlichte google jedoch eine neue Version von Chrome. In Chrome 14 hat google nun den <a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10">Websocket-Draft hybi-10</a> implementiert und dort hat sich vieles grundlegend geändert. Neben einem neuen Handshake werden auch die Datenframes komplett neu codiert.<br />
Ich habe meine Client-Klasse entsprechend angepasst und möchte sie natürlich wieder hier präsentieren, da sie dem ein oder anderen Entwickler sicherlich helfen wird. Desweiteren habe ich die &#8220;Connection-Klasse&#8221; des Websocket-Servers von Nico Kaiser so angepasst, dass sie auch den hybi10-Draft unterstützt.</p>
<p>Viel Spass bei basteln <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong style="text-decoration: underline;">HINWEIS:</strong> Da der Server aktuell ständig weiterentwickelt wird habe ich ein Repository auf Github angelegt. Bitte den jeweils aktuelle Code verwenden: <a href="https://github.com/lemmingzshadow/php-websocket">https://github.com/lemmingzshadow/php-websocket</a></p>
<p><strong style="text-decoration: underline;">UPDATE:</strong> As the project is constantly updated and improved I created a repository on github. Please get the code here: <a href="https://github.com/lemmingzshadow/php-websocket">https://github.com/lemmingzshadow/php-websocket</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>PHP Websocket Client</title>
		<link>http://lemmingzshadow.net/379/php-websocket-client/</link>
		<comments>http://lemmingzshadow.net/379/php-websocket-client/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 13:43:22 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=379</guid>
		<description><![CDATA[Seit einiger Zeit spiele ich immer mal wieder mit Websockets. Allerdings habe ich bisher keinen wirklich funktionstüchtigen, in PHP implementierten Websocket-Client finden können. Also habe ich kurzerhand selbst eine Klasse dafür gebaut welche ich hier natürlich gerne veröffentliche. Absolut minimal, aber für Testzwecke ausreichend. Es wird aktuell der Handshake aus Draft &#8220;draft-ietf-hybi-thewebsocketprotocol-00&#8221; unterstürzt. Getestet habe [...]]]></description>
			<content:encoded><![CDATA[<p>Seit einiger Zeit spiele ich immer mal wieder mit <a href="http://lemmingzshadow.net/tag/websockets/">Websockets</a>. Allerdings habe ich bisher keinen wirklich funktionstüchtigen, in PHP implementierten Websocket-Client finden können. Also habe ich kurzerhand selbst eine Klasse dafür gebaut welche ich hier natürlich gerne veröffentliche. Absolut minimal, aber für Testzwecke ausreichend. Es wird aktuell der Handshake aus Draft &#8220;<a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00">draft-ietf-hybi-thewebsocketprotocol-00</a>&#8221; unterstürzt. Getestet habe ich es mit der aktuellen Version von Chrome (13.0.782) und dem <a href="https://github.com/nicokaiser/php-websocket">Websocket Server von Nico Kaiser</a>.</p>
<p>Hier die Klasse + Beispielaufruf:</p>
<p><strong>ACHTUNG:</strong> Eine aktuellere Version dieser Klasse gibt es hier: <a href="http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/">PHP Websocket Server/Client nach Draft hybi-10</a></p>
<p><span id="more-379"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Very basic websocket client.
 * Supporting handshake from drafts:
 *	draft-hixie-thewebsocketprotocol-76
 *	draft-ietf-hybi-thewebsocketprotocol-00
 * 
 * @author Simon Samtleben &lt;web@lemmingzshadow.net&gt;
 * @version 2011-09-15
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> WebsocketClient
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_Socket</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sendData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// send actual data:</span>
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\x00</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xff</span>&quot;</span> <span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errno</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errstr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$wsData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wsData</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\xff</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$key1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$key2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$key3</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
		<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET /echo HTTP/1.1<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Upgrade: WebSocket<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Connection: Upgrade<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Host: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$host</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$port</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Origin: http://foobar.com<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Sec-WebSocket-Key1: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key1</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Sec-WebSocket-Key2: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key2</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #000088;">$key3</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errno</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errstr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009933; font-style: italic;">/**
		 * @todo: check response here. Currently not implemented cause &quot;2 key handshake&quot; is already deprecated.
		 * See: http://en.wikipedia.org/wiki/WebSocket#WebSocket_Protocol_Handshake
		 */</span>		
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$addSpaces</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #000088;">$addNumbers</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>  
		<span style="color: #000088;">$characters</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!&quot;§$%&amp;/()=[]{}'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$useChars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// select some random chars:    </span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$useChars</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$characters</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// add spaces and numbers:</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$addSpaces</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$useChars</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$addNumbers</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$useChars</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">shuffle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$useChars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$randomString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$useChars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$randomString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$randomString</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$randomString</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$WebSocketClient</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebsocketClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$WebSocketClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1337'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$WebSocketClient</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/379/php-websocket-client/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Named subpatterns in PHP</title>
		<link>http://lemmingzshadow.net/369/named-subpatterns-in-php/</link>
		<comments>http://lemmingzshadow.net/369/named-subpatterns-in-php/#comments</comments>
		<pubDate>Thu, 12 May 2011 08:59:23 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=369</guid>
		<description><![CDATA[Da ich in regulären Ausdrücken gerade häufiger sog. &#8220;benannte Teilmuster&#8221; (named subpatterns) nutze und es mir so vorkommt als würde diese ungemein hilfreiche &#8220;Funktion&#8221; eher selten benutzt, will ich hier kurz darauf hinweisen. Named subpatterns gibt es seit PHP 5.2.2 und sie funktionieren wie folgt: Angenommen ich möchte Daten aus verschiedenen Quellen verwenden, dann kann [...]]]></description>
			<content:encoded><![CDATA[<p>Da ich in regulären Ausdrücken gerade häufiger sog. &#8220;benannte Teilmuster&#8221; (named subpatterns) nutze und es mir so vorkommt als würde diese ungemein hilfreiche &#8220;Funktion&#8221; eher selten benutzt, will ich hier kurz darauf hinweisen. Named subpatterns gibt es seit PHP 5.2.2 und sie funktionieren wie folgt:</p>
<p>Angenommen ich möchte Daten aus verschiedenen Quellen verwenden, dann kann bzw. wird es vorkommen, dass diese Daten unterschiedliche Formate haben. Ein ganz simples Beispiel:</p>
<p>Quelle A: 44793 Bochum &#8211; Sonnig &#8211; 19 Grad<br />
Quelle B: 44793 Bochum &#8211; 19 Grad &#8211; Sonnig</p>
<p>Die gleichen Daten, aber ein andere Reihenfolge.<br />
Wenn ich nun für jede Datenquelle einen reguläre Ausdruck verwende um die Daten zu teilen, hatte man früher oft folgendes Problem:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;44793 Bochum - Sonnig - 19 Grad&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(.+)\s-\s(.+)\s-\s(.+)/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-369"></span><br />
Bei diesem Code finde ich die Temperatur einmal in $temp[3] und einmal in $temp[2]. Somit müsste ich für jede Datenquelle zusätzlich speichern in welchem Feld welcher Wert liegt. Und genau hier kommen die benannten Suchmuster ins Spiel. Durch eine kleine Modifikation des regulären Ausdrucks kann man den Teilmustern Namen geben:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;44793 Bochum - Sonnig - 19 Grad&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(?&lt;ort&gt;.+)\s-\s(?&lt;descr&gt;.+)\s-\s(?&lt;temperatur&gt;.+)/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ergibt dann:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Array
(
    [0] =&gt; 44793 Bochum - Sonnig - 19 Grad
    [ort] =&gt; 44793 Bochum
    [1] =&gt; 44793 Bochum
    [descr] =&gt; Sonnig
    [2] =&gt; Sonnig
    [temperatur] =&gt; 19 Grad
    [3] =&gt; 19 Grad
)</pre></div></div>

<p>Keine Magie, aber ungemein hilfreich wenn man es noch nicht kennt <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/369/named-subpatterns-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mcrypt_create_iv teilweise sehr langsam</title>
		<link>http://lemmingzshadow.net/366/mcrypt_create_iv-teilweise-sehr-langsam/</link>
		<comments>http://lemmingzshadow.net/366/mcrypt_create_iv-teilweise-sehr-langsam/#comments</comments>
		<pubDate>Mon, 09 May 2011 11:19:54 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=366</guid>
		<description><![CDATA[Für ein privates Projekt bastle ich seit einiger Zeit an einem IRC-Bot wobei folgendes Problem auftrat: Sobald Nachrichten in einem IRC-Channel gelesen oder geschrieben wurden hing das Script für einige Sekunden als würde irgendwo ein sleep ausgeführt. Dies war allerdings nicht immer der Fall und trat zudem nicht auf einem Windows System auf. (Weshalb mein [...]]]></description>
			<content:encoded><![CDATA[<p>Für ein privates Projekt bastle ich seit einiger Zeit an einem IRC-Bot wobei folgendes Problem auftrat:<br />
Sobald Nachrichten in einem IRC-Channel gelesen oder geschrieben wurden hing das Script für einige Sekunden als würde irgendwo ein sleep ausgeführt. Dies war allerdings nicht immer der Fall und trat zudem nicht auf einem Windows System auf. (Weshalb mein Xdebug-Profiling erfolglos war). Es blieb mir also nichts anderes übrig als solange Komponenten des Bots zu deaktivieren bis das Problem nicht mehr auftrat. So stelle ich fest dass, das Problem irgendwo in der Klasse für die FiSH-Verschlüsselung lag.<span id="more-366"></span><br />
Bei genauerer Analyse stelle sich heraus dass die Funktion mcrypt_create_iv aus der Mcrypt-Extension Ursache des Problems war. Diese Funktion generiert eine Initialisierungsvektor für die Ver-/Entschlüsselung und braucht dafür teilweise extrem lange. In meinem Fall 5-6 Sekunden. Eine Lösung für das Problem fand ich auf php.net: Statt MCRYPT_DEV_RANDOM kann man MCRYPT_DEV_URANDOM  als Quelle für die benötigen Zufallswerte benutzen und das Problem ist behoben. Ein simple Änderung mit großer Wirkung.</p>
<p>Vorher:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_create_iv</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mcrypt_enc_get_iv_size</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> MCRYPT_DEV_RANDOM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Nacher:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$iv</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mcrypt_create_iv</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mcrypt_enc_get_iv_size</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$td</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> MCRYPT_DEV_URANDOM<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/366/mcrypt_create_iv-teilweise-sehr-langsam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asynchrone PHP Prozesse mit Gearman</title>
		<link>http://lemmingzshadow.net/347/asynchrone-php-prozesse-mit-gearman/</link>
		<comments>http://lemmingzshadow.net/347/asynchrone-php-prozesse-mit-gearman/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 16:03:28 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Gearman]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webtechnik]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=347</guid>
		<description><![CDATA[Es kommt immer wieder vor, dass man aus einem PHP-Script heraus ein Anderes aufrufen möchte welches dann eine bestimmt Aufgabe erledigt. Dies ist z.B. sinnvoll wenn die Aufgabe länger dauert und man nicht im Script darauf warten möchte, wie etwa beim Erstellen von Bildern in verschiedenen Größen. Ich hatte bereits vor einiger Zeit über eine [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://lemmingzshadow.net/files/2011/03/gearman.gif" alt="Gearman" title="Gearman" width="80" height="80" style="float: left; padding: 5px;" /> Es kommt immer wieder vor, dass man aus einem PHP-Script heraus ein Anderes aufrufen möchte welches dann eine bestimmt Aufgabe erledigt. Dies ist z.B. sinnvoll wenn die Aufgabe länger dauert und man nicht im Script darauf warten möchte, wie etwa beim Erstellen von Bildern in verschiedenen Größen.<br />
Ich hatte bereits vor einiger Zeit über eine Möglichkeit berichtet <a href="http://lemmingzshadow.net/6/php-scripte-im-hintergrund-ausfuhren/">PHP-Script im Hintergrund auszuführen</a>.<br />
Diese Möglichkeit ist allerdings nicht wirklich schön und hat auch einige Nachteile. Z.B. kann man nur schwer abfragen wie der aktuelle Status des Scripts ist und auch die Verteilung auf verschiedene Server ist nicht trivial. Darum möchte ich hier eine wesentlich elegantere Möglichkeit vorstellen PHP-Prozesse asynchron laufen zu lassen. Und zwar mit Hilfe von <a href="http://gearman.org/">Gearman</a>:<span id="more-347"></span></p>
<p>Gearman ist ein Jobserver und ermöglicht es Aufgaben auf verschiedene Prozesse und/oder Maschinen auszulagern. Dabei arbeitet man mit sogenannten &#8220;Workern&#8221; die auf einem beliebigen Server darauf warten Aufgaben zu erledigen. Besonders schön ist, dass diese Worker ebenfalls in PHP programmiert werden können. Zunächst jedoch ein paar Worte zur Installation.</p>
<p>Auf einem Debian Squeeze System ist die Installation denkbar einfach. Einfach den Jobserver via Aptitude oder apt-get installieren. Das Paket heisst <a href="http://packages.debian.org/squeeze/gearman">&#8220;gearman&#8221;</a>. Im init.d Ordner liegt dann auch direkt ein Script mit dem der Server gestartet werden kann:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/etc/init.d/gearman-job-server start</pre></div></div>

<p>Um den Gearman Server in PHP &#8220;ansprechen&#8221; zu können benötigt man nun noch die <a href="http://de.php.net/manual/en/book.gearman.php">Gearman-Extension</a> welche über PECL installiert werden kann.<br />
Hinweis: Es wird das Paket &#8220;php5-dev&#8221; benötigt. Falls dieses noch nicht installiert ist sollte man das an dieser Stelle tun.</p>
<p>Dann die PHP-Extenstion über PECL installieren:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">pecl install gearman</pre></div></div>

<p>Hinweis: Falls das Paket hier nicht installiert werden kann weil es eine Beta Version ist, stattdessen folgenden Befehl verwenden:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">pecl install gearman-beta</pre></div></div>

<p>Damit sollte die Extension erstellt sein und kann in der php.ini geladen werden. Dazu einfache folgendes in der php.ini ergänzen:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">extension = gearman.so</pre></div></div>

<p>Hinweis: Da die Worker normalerweise als CLI-Programme laufen, die entsprechende php.ini nicht vergessen.</p>
<p>Nun sollte alles soweit sein, dass Gearman verwendet werden kann.</p>
<p>Zunächst brauchen wir einen Worker welcher im Hintergrund läuft und darauf wartet Aufgaben zu erledigen. Hier ein Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> WorkerExample
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_GearmanWorker</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span>  __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_GearmanWorker <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GearmanWorker<span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_GearmanWorker<span style="color: #339933;">-&gt;</span><span style="color: #004000;">addServer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4730</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_startupWorker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _startupWorker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_GearmanWorker<span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFunction</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foobar'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foobar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_GearmanWorker<span style="color: #339933;">-&gt;</span><span style="color: #004000;">work</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> foobar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Job</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Job</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">workload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// do some work here...</span>
		<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$Worker</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WorkerExample<span style="color: #339933;">;</span></pre></div></div>

<p>Diesen Worker kann man nun z.B. als worker.php speichern und dann zum testen in einem Screen laufen lassen:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">php worker.php</pre></div></div>

<p>Nun brauchen wir noch ein Script welches diesen Worker aufruft, der sogenannte Client:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$Client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GearmanClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addServer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4730</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'foo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">42</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'bar'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1337</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">doBackground</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foobar'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Wenn nun dieser Client aufgerufen wird sollte man in dem Screen in dem der Worker läuft eine Ausgabe der übergebenen Parameter sehen.<br />
Im Code sieht man sofort dass die IP des Servers auf dem Gearman läuft angegeben wird. Hier kann natürlich auch ein anderer Server als localhost benutzt werden. Mit &#8220;doBackground&#8221; wird der Worker aufgerufen und das Script läuft direkt weiter ohne auf irgendeine Antwort des Workers zu warten.</p>
<p>Über die vielen weiteren Möglichkeiten des Gearman-Servers kann man sich am besten informieren wenn man einen Blick auf die Methoden der <a href="http://de3.php.net/manual/en/book.gearman.php">Gearman-Extension auf php.net</a> wirft. Und nun viel Spass beim experimentieren. <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/347/asynchrone-php-prozesse-mit-gearman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SFTP Upload mit PHP</title>
		<link>http://lemmingzshadow.net/301/sftp-upload-mit-php/</link>
		<comments>http://lemmingzshadow.net/301/sftp-upload-mit-php/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 19:49:27 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SFTP]]></category>
		<category><![CDATA[Webtechnik]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=301</guid>
		<description><![CDATA[Seit einiger Zeit bietet PHP mit der SSH2-Library einige Methoden um das SFTP-Subsystem von SSH zu nutzen. Leider fehlt eine Methode um Dateien per SFTP hochzuladen. Zwar existiert mit der Methode ssh2_scp_send eine Möglichkeit Dateien über einer SSH-Verbindung hochzuladen, allerdings wird hier das SCP-Protokoll benutzt. Sollte der verwendete Account serverseitig jedoch auf SFTP beschränkt sein [...]]]></description>
			<content:encoded><![CDATA[<p>Seit einiger Zeit bietet PHP mit der <a href="http://de.php.net/manual/en/book.ssh2.php">SSH2-Library</a> einige Methoden um das SFTP-Subsystem von SSH zu nutzen. Leider fehlt eine Methode um Dateien per SFTP hochzuladen. Zwar existiert mit der Methode <em>ssh2_scp_send</em> eine Möglichkeit Dateien über einer SSH-Verbindung hochzuladen, allerdings wird hier das SCP-Protokoll benutzt. Sollte der verwendete Account serverseitig jedoch auf SFTP beschränkt sein funktioniert diese Methode nicht.<br />
Um dennoch Dateien per SFTP hochladen zu können kann man sich mit der Methode <em>fopen</em> und dem <a href="http://de.php.net/manual/en/wrappers.ssh2.php">ssh2-sftp Wrapper</a> eine funktionierende Lösung basteln. <span id="more-301"></span></p>
<p>Eine sftp-upload Funktion könnte beispielsweise so aussehen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sftp_putfile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$local_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remote_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mode</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0664</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$remote_file</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$remote_file</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$remote_file</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$remote_file</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sftp_stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ssh2.sftp://'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sftp_connection</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$remote_file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$sftp_stream</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_sftp_error</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$data_to_send</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$local_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data_to_send</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_sftp_error</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sftp_stream</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data_to_send</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_sftp_error</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sftp_stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Diese beispielhafte Methode stammt aus einer SFTP Klasse die ich vor kurzem für eine Projekt geschrieben habe. Die komplette Klasse habe ich <a href="http://lemmingzshadow.net/files/2010/08/class.sftp.php.txt">hier zum download</a> hinterlegt.</p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/301/sftp-upload-mit-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter API mit oAuth nutzen</title>
		<link>http://lemmingzshadow.net/295/twitter-api-mit-oauth-nutzen/</link>
		<comments>http://lemmingzshadow.net/295/twitter-api-mit-oauth-nutzen/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 11:58:48 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[oAuth]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Webtechnik]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=295</guid>
		<description><![CDATA[Am 30. Juni wird Twitter die Standard Authentifizierung der Twitter API abschalten. Bis dahin sollte man seine Scripte so umstellen, dass sie oAuth benutzen. Wie lange man dafür noch Zeit hat erfährt man übrigens hier: http://www.countdowntooauth.com/ Da es mittlerweile schon einige PHP Klassen gibt welche oAuth unterstützen ist die Umstellung relativ einfach zu bewerkstelligen. Hier [...]]]></description>
			<content:encoded><![CDATA[<p>Am 30. Juni wird Twitter die Standard Authentifizierung der Twitter API abschalten. Bis dahin sollte man seine Scripte so umstellen, dass sie oAuth benutzen. Wie lange man dafür noch Zeit hat erfährt man übrigens hier: <a href="http://www.countdowntooauth.com/">http://www.countdowntooauth.com/</a> <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Da es mittlerweile schon einige PHP Klassen gibt welche oAuth unterstützen ist die Umstellung relativ einfach zu bewerkstelligen. Hier ein kleines Tutorial:</p>
<p>Zunächst muss man auf <a href="http://dev.twitter.com/">http://dev.twitter.com/</a> eine neue &#8220;App&#8221; anlegen. (Vorher einloggen) Der Prozess ist selbsterklärend. Nachdem man die App angelegt hat erhält man einen &#8220;Consumer key&#8221; und ein &#8220;Consumer secret&#8221;. Diese beiden Strings benötigen wir später für die Authentifizierung. Weiterhin braucht man den &#8220;oAuth Token&#8221; und das &#8220;oAuth Token Secret&#8221;. Um diese zu bekommen oben auf <a href="http://dev.twitter.com/apps">Your apps</a> klicken. Dann auf &#8220;Edit Details&#8221; der entsprechen App. Nach zwei weiteren Klicks auf &#8220;Application detail&#8221; (rechts) und &#8220;My Access Token&#8221; (auch rechts) hat man alle benötigten Tokens und Passwörter zusammen die man in einem PHP-Script benötigt.<span id="more-295"></span></p>
<p>Nun kann man entweder selbst damit anfangen eine oAuth Authentifizierung zu coden oder man benutzt eine der fertigen Klassen. Ich habe für dieses Beispiel eine fertige <a href="http://github.com/abraham/twitteroauth">oAuth Klasse von Abraham Williams</a> benutzt.<br />
Hier ein kleines Codebeispiel für die Authentifizierung mit oAuth und dem anschließenden posten eines Tweets:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$consumer_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'insert_key'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$consumer_secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'insert_secret'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$access_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'insert_key'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$access_secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'insert_secret'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitteroauth/twitteroauth.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$twitter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterOAuth <span style="color: #009900;">&#40;</span><span style="color: #000088;">$consumer_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$consumer_secret</span><span style="color: #339933;">,</span> <span style="color: #000088;">$access_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$access_secret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$twitter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'statuses/update'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Testing oAuth. Please ignore...'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/295/twitter-api-mit-oauth-nutzen/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Konstanten für Datumsformate in PHP</title>
		<link>http://lemmingzshadow.net/245/konstanten-fuer-datumsformate-in-php/</link>
		<comments>http://lemmingzshadow.net/245/konstanten-fuer-datumsformate-in-php/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 17:06:06 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=245</guid>
		<description><![CDATA[Andauernd vergesse ich dass es Sie gibt: Konstanten für verschiedene Datumsformate. Ausserdem sind Sie (wie ich finde) bei php.net nur schlecht dokumentiert. Darum hier nun für alle ein Codebeispiel und der Link zu den restlichen Konstanten. Folgender Code würde z.B. soetwas ausgeben: Wednesday, 10-Feb-10 18:02:49 CET 1 echo date&#40;DATE_COOKIE, time&#40;&#41;&#41;; Alle dieser nützlichen Konstanten sind [...]]]></description>
			<content:encoded><![CDATA[<p>Andauernd vergesse ich dass es Sie gibt: Konstanten für verschiedene Datumsformate. Ausserdem sind Sie (wie ich finde) bei php.net nur schlecht dokumentiert. Darum hier nun für alle ein Codebeispiel und der Link zu den restlichen Konstanten.<br />
Folgender Code würde z.B. soetwas ausgeben:<br />
<em>Wednesday, 10-Feb-10 18:02:49 CET</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span>DATE_COOKIE<span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Alle dieser nützlichen Konstanten sind hier dokumentiert: <a href="http://php.net/manual/en/class.datetime.php"><strong>Datumskonstanten bei php.net</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/245/konstanten-fuer-datumsformate-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

