<?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.netlemmingzshadow.net - a webdevel&#039;s weblog</title>
	<atom:link href="http://lemmingzshadow.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://lemmingzshadow.net</link>
	<description>a webdevel&#039;s weblog</description>
	<lastBuildDate>Fri, 27 Jan 2012 20:18:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>News 2012-01-27</title>
		<link>http://lemmingzshadow.net/436/news-2012-01-27/</link>
		<comments>http://lemmingzshadow.net/436/news-2012-01-27/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 20:18:19 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=436</guid>
		<description><![CDATA[Ganz kurzes Update: Habe ein neues Theme, das vorherige war inzwischen etwas in die Jahre gekommen. Auf isitfriday.info ist wieder alles beim Alten. Mit dem Websocket-Server geht es gut voran &#8211; Support für wss ist bald fertig. An dieser Stelle vielen Dank für die ganzen Mails mit Bugfixes etc. Ich bin dran]]></description>
			<content:encoded><![CDATA[<p>Ganz kurzes Update: Habe ein neues Theme, das vorherige war inzwischen etwas in die Jahre gekommen. Auf <a href="http://isitfriday.info" title="isitfriday.info">isitfriday.info</a> ist wieder alles beim Alten. Mit dem <a href="https://github.com/lemmingzshadow/php-websocket" title="PHP Websocket Server">Websocket-Server</a> geht es gut voran &#8211; Support für wss ist bald fertig. An dieser Stelle vielen Dank für die ganzen Mails mit Bugfixes etc. Ich bin dran <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/436/news-2012-01-27/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PPTP VPN Tunnel &#8211; Ein paar Tipps</title>
		<link>http://lemmingzshadow.net/411/pptp-vpn-tunnel-ein-paar-tipps/</link>
		<comments>http://lemmingzshadow.net/411/pptp-vpn-tunnel-ein-paar-tipps/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 21:52:25 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[PPTP]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=411</guid>
		<description><![CDATA[Vor kurzem habe ich einen VPN-Server aufgesetzt und habe mich dabei für das PPTP entschieden. Auf die grundlegende Installation unter Debian möchte ich hier nicht eingehen denn dafür gibt es bereits genügen Anleitungen im Netz. (z.B. hier) Allerdings waren (zumindest bei mir) nach der Installation noch einige kleine Kniffe notwendig bis der Tunnel vernünftig lief. [...]]]></description>
			<content:encoded><![CDATA[<p>Vor kurzem habe ich einen VPN-Server aufgesetzt und habe mich dabei für das PPTP entschieden. Auf die grundlegende Installation unter Debian möchte ich hier nicht eingehen denn dafür gibt es bereits genügen Anleitungen im Netz. (z.B. <a href="http://www.howtogeek.com/51237/setting-up-a-vpn-pptp-server-on-debian/">hier</a>)</p>
<p>Allerdings waren (zumindest bei mir) nach der Installation noch einige kleine Kniffe notwendig bis der Tunnel vernünftig lief. An dieser Stelle noch kurz der Hinweis, dass als Clients Windows 7 bzw. Windows XP Rechner zum Einsatz kommen.</p>
<p><strong>Problem 1:</strong> Clients können sich einwandfrei verbinden, es können jedoch keine Daten empfangen werden.<br />
Lösung: Damit der Server empfangene Daten zu den Clients &#8220;weiterrouten&#8221; kann ist eine IPTables Regel notwendig. Bei mir brachte folgendes die Lösung:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">iptables --table nat --append POSTROUTING  --out-interface eth0 --jump MASQUERADE</pre></div></div>

<p><span id="more-411"></span><br />
<strong>Problem 2:</strong> Der Tunnel funktioniert grundlegend, die Verbindung &#8220;friert jedoch bei gößeren Datenmenegen ein&#8221;.<br />
Lösung: Auch hier hilft ein Regeln in den IPTables weiter:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">iptables --append FORWARD --protocol tcp --tcp-flags SYN,RST SYN --jump TCPMSS --clamp-mss-to-pmtu</pre></div></div>

<p>Desweiteren habe ich zur Lösung dieses Problems die <a href="http://de.wikipedia.org/wiki/Maximum_Transmission_Unit">MTU</a> und <a href="http://de.wikipedia.org/wiki/Link_Control_Protocol#Maximum_Receive_Unit_.28MRU.29">MRU</a> angepasst und auf einen Wert von 1400 eingestellt.<br />
Diese Werte können in der Datei <em>/etc/ppp/pptpd-options</em> angepasst werden.</p>
<p><strong>Problem 3:</strong> Clients werden immer wieder vom VPN-Server getrennt.<br />
Lösung: In meinem Fall brachten mich diese Zeilen in den Logfiles auf die Lösung:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">No response to 4 echo-requests
Serial link appears to be disconnected.</pre></div></div>

<p>Offensichtlich antworteten einige Clients nicht (oder nicht zuverlässig) auf die vom Server verschickten <a href="http://de.wikipedia.org/wiki/Link_Control_Protocol">LCP-Echo-Requests</a>. Nachdem auch die Erhöhung der maximal nicht beantworteten Requests keine Abhilfe brachte habe ich die Echo-Anfragen schließlich komplett deaktiviert. Dies kann man in der Datei <em>/etc/ppp/options</em> erledigen indem man folgende zwei Werte auf 0 setzt:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">lcp-echo-interval 0
lcp-echo-failure 0</pre></div></div>

<p>Ich hoffe dieser Beitrag kann helfen falls jemand auf die gleichen Probleme stößt, z.B. ich wenn ich in ein paar Monaten mal wieder einen pptpd aufsetze <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/411/pptp-vpn-tunnel-ein-paar-tipps/feed/</wfw:commentRss>
		<slash:comments>6</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>36</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>Aktualisiertes Projekt: isitfriday.info</title>
		<link>http://lemmingzshadow.net/372/aktualisiertes-projekt-isitfriday-info/</link>
		<comments>http://lemmingzshadow.net/372/aktualisiertes-projekt-isitfriday-info/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 19:47:53 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[projekt]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=372</guid>
		<description><![CDATA[Seit letzter Woche Freitag ist auf der Domain isitfriday.info (vorher isitfriday.de) endlich etwas mehr zu sehen als Ja oder Nein. Es gibt ein neues Design und jede Woche neuen Inhalt. (Video, Bild, Text, etc.) Auf der To-Do Liste steht noch die Archiv-Funktion sowie eine Möglichkeit den Inhalt der Woche zu kommentieren bzw. zu diskutieren. Kurz [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://lemmingzshadow.net/files/2011/07/iif-150x150.png" alt="" title="iif" width="150" height="150" class="alignleft size-thumbnail wp-image-373" style="margin:5px;" />Seit letzter Woche Freitag ist auf der Domain <a href="http://isitfriday.info/">isitfriday.info</a> (vorher isitfriday.de) endlich etwas mehr zu sehen als Ja oder Nein. Es gibt ein neues Design und jede Woche neuen Inhalt. (Video, Bild, Text, etc.) Auf der To-Do Liste steht noch die Archiv-Funktion sowie eine Möglichkeit den Inhalt der Woche zu kommentieren bzw. zu diskutieren.</p>
<p>Kurz zur Technik: Das Projekt ist eine komplette Eigenentwicklung, ich habe kein Framework benutzt. Als Templateengine verwende ich <a href="http://www.smarty.net/">Smarty</a>. Es werden einige HTML5- und CSS3-Elemente verwendet. Als Basis diente die <a href="http://html5boilerplate.com/">HTML5-Boilerplate</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/372/aktualisiertes-projekt-isitfriday-info/feed/</wfw:commentRss>
		<slash:comments>1</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>Wechsel von PHP-CGI zu PHP-FPM</title>
		<link>http://lemmingzshadow.net/360/wechsel-von-php-cgi-zu-php-fpm/</link>
		<comments>http://lemmingzshadow.net/360/wechsel-von-php-cgi-zu-php-fpm/#comments</comments>
		<pubDate>Sun, 08 May 2011 17:48:18 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[PHP-FPM]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=360</guid>
		<description><![CDATA[Da ich hier schon längere Zeit nichts mehr geschrieben habe, habe ich beschlossen nun auch kürzere, weniger aufwendige Artikel zu veröffentlichen, um hier mal wieder etwas Leben in die Bude zu bekommen. Jetzt aber zum Thema: Aus einem mir unbekannten Grund verabschiedeten sich auf meinem Debian Squeeze Server die PHP-CGI Prozesse mit folgender Meldung im [...]]]></description>
			<content:encoded><![CDATA[<p>Da ich hier schon längere Zeit nichts mehr geschrieben habe, habe ich beschlossen nun auch kürzere, weniger aufwendige Artikel zu veröffentlichen, um hier mal wieder etwas Leben in die Bude zu bekommen. Jetzt aber zum Thema:</p>
<p>Aus einem mir unbekannten Grund verabschiedeten sich auf meinem Debian Squeeze Server die PHP-CGI Prozesse mit folgender Meldung im Error-Log:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">(mod_fastcgi.c.3001) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead</pre></div></div>

<p>Ich habe zwar eine generelle Lösung für dieses Problem gefunden (<a href="http://www.debianroot.de/server/loesung-fuer-das-lighttpd-problem-backend-is-overloaded-1093.html">Link</a>), diese konnte ich bei meiner Serverkonfiguration aber leider nicht anwenden. Da ich mehrere PHP-CGI-Pools mit verschiedenen UIDs/GIDs starte und diese in der Lighttpd-Config über die Sockets zuordne, konnte ich hier den &#8220;var.PID&#8221; Teil nicht anhängen. Davon abgesehen hatte es vorher viele Monate ohne diese Änderung funktioniert. Also habe ich mich kurzerhand dazu entschlossen zu <a href="http://php-fpm.org/">PHP-FPM</a> zu wechseln.<br />
<span id="more-360"></span><br />
Leider gibt es das php-fpm Paket (noch?) nicht im Debian-Squeeze Repository deswegen habe ich die Paketquellen von <a href="http://www.dotdeb.org/">Dotdeb</a> verwendet. Die Umstellung funktionierte wunderbar einfach, denn man kann PHP-CGI und PHP-FPM problemlos parallel laufen lassen und einen Vhost nach dem anderen umstellen.<br />
Ein recht gutes Tutorial zur Konfiguration von PHP-FPM gibt es <a href="http://publications.jbfavre.org/web/php-fpm-apps-server-nginx.en">hier</a>. Nachdem FPM konfiguriert und gestartet ist kann man in den Vhost-Konfigurationen von Lighttpd einfach den PHP-CGI Teil durch die neue FPM-Konfiguration ersetzen. Das sieht in etwa so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">fastcgi.server = ( &quot;.php&quot; =&gt;
      ( &quot;localhost&quot; =&gt;
        (
          &quot;host&quot; =&gt; &quot;127.0.0.1&quot;,
          &quot;port&quot; =&gt; &quot;9001&quot;
        )
      )
    )</pre></div></div>

<p>Ein enormer Vorteil von PHP-FPM: Man kann mehrere Pools konfigurieren die mit unterschiedlichen UIDs/GIDs laufen, was die Sicherheit auf dem Server ein gutes Stück erhöht.</p>
<p>Mein Fazit: Die Umstellung von PHP-CGI auf PHP-FPM ist relativ leicht zu bewerkstelligen und den Aufwand in jeden Fall wert!</p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/360/wechsel-von-php-cgi-zu-php-fpm/feed/</wfw:commentRss>
		<slash:comments>1</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>obsession-design.de &#8211; Bis auf weiteres offline</title>
		<link>http://lemmingzshadow.net/322/obsession-design-de-bis-auf-weiteres-offline/</link>
		<comments>http://lemmingzshadow.net/322/obsession-design-de-bis-auf-weiteres-offline/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 17:00:00 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[obsession]]></category>
		<category><![CDATA[projekt]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=322</guid>
		<description><![CDATA[Nach ca. 10 Jahren habe ich beschlossen mein Projekt obsession-design.de abzuschalten und auf dieses Blog weiter zu leiten. Diese Entscheidung habe ich seit längerem vor mir her geschoben, da man ja doch immer ein wenig an seinen Projekten hängt. Allerdings war die Seite nun schon seit geraumer Zeit nur noch aus nostalgischen Gründen online und [...]]]></description>
			<content:encoded><![CDATA[<p>Nach ca. 10 Jahren habe ich beschlossen mein Projekt obsession-design.de abzuschalten und auf dieses Blog weiter zu leiten.<br />
Diese Entscheidung habe ich seit längerem vor mir her geschoben, da man ja doch immer ein wenig an seinen Projekten hängt. Allerdings war die Seite nun schon seit geraumer Zeit nur noch aus nostalgischen Gründen online und wurde nicht mehr aktualisiert. Darum nun dieser Schritt.</p>
<p>Noch kurz 1-2 Worte zur Begründung: <span id="more-322"></span>Nun, es ist schlicht so, dass ich zu wenig Zeit für das Projekt obsession-design.de habe. Neben Beruf und einigen kleineren privaten Webprojekten bleibt leider keine Zeit drei Scripte weiter zu entwickeln und angemessenen Support zu leisten. Darum sind die Scripte welche ich auf obsession-design.de angeboten habe mittlerweile hoffnungslos veraltet. Ich möchte an dieser Stelle auch davon abraten die Scripte ODGB, ODKA oder ODIG produktiv einzusetzen ohne sie vorher gründlich auf Sicherheitslücken zu prüfen, denn aufgrund meiner mangelnden Erfahrung zu Zeiten als ich die Scripte programmiert habe, liegt doch sicherlich einiges im argen. <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <br />
Fall dennoch jemand eins der Scripte benötigt finden sich die Download-Links am Ende dieses Beitrages.</p>
<p>Ich möchte nicht ausschließen, dass ich vielleicht irgendwann nicht doch nochmal mit einer 8. Version von obsession-design.de neu starte, aber bis dahin werden mit Sicherheit noch ein paar weitere Jahre ins Land ziehen.</p>
<p>Zum Schluss noch ein obsession-design.de Rückblick in Bildern und die jeweils letzen Versionen meiner Scripte:<br />
<a href="http://lemmingzshadow.net/files/2011/01/obsession_v1.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v1-150x150.jpg" alt="obsession-design.de v1" title="obsession_v1" width="150" height="150" class="alignleft size-thumbnail wp-image-323" style="padding: 3px;" /></a> <a href="http://lemmingzshadow.net/files/2011/01/obsession_v2.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v2-150x150.jpg" alt="" title="obsession-design.de v2" width="150" height="150" class="alignleft size-thumbnail wp-image-325" style="padding: 3px;" /></a> <a href="http://lemmingzshadow.net/files/2011/01/obsession_v3.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v3-150x150.jpg" alt="" title="obsession-design.de v3" width="150" height="150" class="alignleft size-thumbnail wp-image-327" style="padding: 3px;" /></a> <a href="http://lemmingzshadow.net/files/2011/01/obsession_v4.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v4-150x150.jpg" alt="" title="obsession-design.de v4" width="150" height="150" class="alignleft size-thumbnail wp-image-328" style="padding: 3px;" /></a> <a href="http://lemmingzshadow.net/files/2011/01/obsession_v5.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v5-150x150.jpg" alt="" title="obsession-design.de v5" width="150" height="150" class="alignleft size-thumbnail wp-image-329" style="padding: 3px;" /></a> <a href="http://lemmingzshadow.net/files/2011/01/obsession_v6.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v6-150x150.jpg" alt="" title="obsession-design.de v6" width="150" height="150" class="alignleft size-thumbnail wp-image-330" style="padding: 3px;" /></a> <a href="http://lemmingzshadow.net/files/2011/01/obsession_v7.jpg" rel="facebox"><img src="http://lemmingzshadow.net/files/2011/01/obsession_v7-150x150.jpg" alt="" title="obsession-design.de v7" width="150" height="150" class="alignleft size-thumbnail wp-image-331" style="padding: 3px;" /></a></p>
<div style="clear: both; padding-top:10px;"></div>
<ul>
<li><a href="http://lemmingzshadow.net/files/2011/01/odgb.v1.2.rar"><strong>Download ODGB v1.2</strong></a></li>
<li><a href="http://lemmingzshadow.net/files/2011/01/odig.v1.1.rar"><strong>Download ODIG v1.1</strong></a></li>
<li><a href="http://lemmingzshadow.net/files/2011/01/odka.v2.3.rar"><strong>Download ODKA v2.3</strong></a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/322/obsession-design-de-bis-auf-weiteres-offline/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

