<?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>Ariel Sommeria .com</title>
	<atom:link href="http://arielsommeria.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://arielsommeria.com/blog</link>
	<description>Articles about and around Amfphp and Baguette AMF</description>
	<lastBuildDate>Tue, 02 Feb 2016 11:36:47 +0000</lastBuildDate>
	<language>en-GB</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Amfphp and Baguette AMF update</title>
		<link>http://arielsommeria.com/blog/2016/02/02/amfphp-and-baguette-amf-update/</link>
		<comments>http://arielsommeria.com/blog/2016/02/02/amfphp-and-baguette-amf-update/#comments</comments>
		<pubDate>Tue, 02 Feb 2016 11:29:53 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorised]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=490</guid>
		<description><![CDATA[I just made a minor Amfphp/Baguette AMF release. Details here http://www.silexlabs.org/updates-for-amfphp-and-baguette-amf/]]></description>
				<content:encoded><![CDATA[<p>I just made a minor Amfphp/Baguette AMF release.</p>
<p>Details here <a href="http://www.silexlabs.org/updates-for-amfphp-and-baguette-amf/%20">http://www.silexlabs.org/updates-for-amfphp-and-baguette-amf/ </a></p>
<p><a href="http://arielsommeria.com/blog/wp-content/uploads/2016/02/amf-php-schema3-sans-fond.jpg"><img class="aligncenter wp-image-493 size-medium" src="http://arielsommeria.com/blog/wp-content/uploads/2016/02/amf-php-schema3-sans-fond-300x196.jpg" alt="amf-php-schema3-sans-fond" width="300" height="196" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2016/02/02/amfphp-and-baguette-amf-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amfphp 2.2.1 released</title>
		<link>http://arielsommeria.com/blog/2014/08/06/amfphp-2-2-1-released/</link>
		<comments>http://arielsommeria.com/blog/2014/08/06/amfphp-2-2-1-released/#comments</comments>
		<pubDate>Wed, 06 Aug 2014 07:36:13 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=441</guid>
		<description><![CDATA[I just released a small update to Amfphp, version 2.2.1. It&#8217;s mostly a bugfix release. The changelog is below. Get Amfphp 2.2.1 here. fix basic typing of parameters in client generator fix error message handling in back office fix flex message monitoring fix API doc other small bugfixes]]></description>
				<content:encoded><![CDATA[<p>I just released a small update to Amfphp, version 2.2.1.</p>
<p>It&#8217;s mostly a bugfix release. The changelog is below. <a href="http://www.silexlabs.org/amfphp/downloads/">Get Amfphp 2.2.1 here</a>.</p>
<div id="LC3">fix basic typing of parameters in client generator</div>
<div id="LC4">fix error message handling in back office</div>
<div id="LC5">fix flex message monitoring</div>
<div id="LC6">fix API doc</div>
<div id="LC7">other small bugfixes</div>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2014/08/06/amfphp-2-2-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amfphp 2.2 Profiler Released</title>
		<link>http://arielsommeria.com/blog/2013/12/16/amfphp-2-2-profiler-released/</link>
		<comments>http://arielsommeria.com/blog/2013/12/16/amfphp-2-2-profiler-released/#comments</comments>
		<pubDate>Mon, 16 Dec 2013 15:13:03 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=412</guid>
		<description><![CDATA[I just released Amfphp 2.2. Profiler!  The main feature is a performance profiler. The idea behind these new features is to help you better understand how your server shall perform live, and to give you easy access to the information you need to eliminate bottlenecks and fine-tune performance.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.silexlabs.org/200755/the-blog/amfphp-2-2-profiler-released/">I just released Amfphp 2.2. Profiler</a>!  The main feature is a performance profiler. The idea behind these new features is to help you better understand how your server shall perform live, and to give you easy access to the information you need to eliminate bottlenecks and fine-tune performance.</p>
<p style="text-align: center;"><a href="http://arielsommeria.com/blog/wp-content/uploads/2013/12/Amfphp-Profiler-Screenshot.png"></a><img class="aligncenter" title="Amfphp Profiler " src="http://arielsommeria.com/blog/content/Amfphp%20Profiler%20Screenshot.png" alt="" width="432" height="322" /></p>
<p style="text-align: center;">
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2013/12/16/amfphp-2-2-profiler-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking AMF Objects</title>
		<link>http://arielsommeria.com/blog/2013/10/31/hacking-amf-objects/</link>
		<comments>http://arielsommeria.com/blog/2013/10/31/hacking-amf-objects/#comments</comments>
		<pubDate>Thu, 31 Oct 2013 11:11:26 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=403</guid>
		<description><![CDATA[While working on the upcoming AmfPHP 2.2 I came upon an interesting challenge: Sending AMF typed objects without knowing the types at compile time. This would allow users of the service browser to send typed objects both with JSON and AMF. The difficulty is the following: For Flash to send an object as typed, you [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>While working on the upcoming <a href="http://silexlabs.org/amfphp/">AmfPHP</a> 2.2 I came upon an interesting challenge: <strong>Sending <a href="www.baguetteamf.com/documentation/why-amf/">AMF</a> typed objects without knowing the types at compile time.</strong></p>
<p>This would allow users of the <a href="http://www.silexlabs.org/amfphp/documentation/using-the-back-office/service-browser/">service browser</a> to send typed objects both with JSON and AMF.<br />
The difficulty is the following: For Flash to send an object as typed, you must provide an alias for its class. This can be done either with the <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html">RemoteClass</a> meta data tag, or with <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html">registerClassAlias</a>. This works fine, but is designed with the idea that you know what the alias shall be at compile time. So I had to find a workaround so that the user can state:</p>
<blockquote><p>&#8220;take this object, use this alias, and send it to the server. &#8220;</p></blockquote>
<p><span id="more-403"></span></p>
<p>So I ended up doing the following:</p>
<ol>
<li>I created some <a href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f89.html">dynamic</a> empty dummy classes, and made sure they were included in the compiled SWF by including a reference to them in the code.
<pre class="brush: php">
package
{
public dynamic class Dummy0
{

}
}
</pre>
<p>The classes are public so that I can find them with <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName()">getDefinitionByName</a> ,and dynamic so that I can add things to them at runtime.<br />
and the reference in my main class:</p>
<pre class="brush: php">
var dummyRef:Class = Dummy0;
</pre>
</li>
<li>For each new object that needs to be sent that is marked with an alias, I replace it with one of my dummy classes, and call registerClassAlias so that the used dummy is sent with the right alias. The dummyClass is stored in a dictionary, so that I can reuse it for another object with the same alias.
<pre class="brush: php">
var dummyClass:Class = null;

if(!type2Class[explicitType]){
dummyClass = getDefinitionByName(&quot;Dummy&quot; + numUsedDummyClasses) as Class;
type2Class[explicitType] = dummyClass;
numUsedDummyClasses++;
}else{
dummyClass = type2Class[explicitType];
}
</pre>
</li>
<li>And I tunnel down the object recursively to make sure this works on many levels.</li>
</ol>
<p>Is this a hack? Indeed? I would very much like to find a cleaner way to do this. I have considered messing directly with the byte code, but this seems a bit heavy handed.</p>
<p>It&#8217;s also only part of the problem: I would very much like to be able to receive typed objects from the server about which the client knows nothing and still be able to retrieve the type. The Flash player unfortunately does not allow this.</p>
<p>The full code as it stands is below. <a href="https://github.com/silexlabs/amfphp-2.0/tree/master/AmfCaller">It can also be found online here</a>.</p>
<pre class="brush: php">
package
{

import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.net.NetConnection;
import flash.net.Responder;
import flash.net.getClassByAlias;
import flash.net.registerClassAlias;
import flash.utils.Dictionary;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;

/**
* provides AMF calling functionality to the service browser via External Interface.
* exposes a &quot;call&quot; method, a &quot;isAlive&quot; method, and uses 1 callback: &quot;onResult&quot;
* */
public class AmfCaller extends Sprite
{
private var numUsedDummyClasses:int = 0;
private var type2Class:Dictionary = new Dictionary();

public function AmfCaller()
{
ExternalInterface.addCallback(&quot;call&quot;, call);
ExternalInterface.addCallback(&quot;isAlive&quot;, isAlive);

//need this to make sure compiler includes dummy classes
var dummyRef:Class = Dummy0;
dummyRef = Dummy1;
dummyRef = Dummy2;
dummyRef = Dummy3;
dummyRef = Dummy4;
dummyRef = Dummy5;
dummyRef = Dummy6;
dummyRef = Dummy7;
dummyRef = Dummy8;
dummyRef = Dummy9;
dummyRef = Dummy10;
dummyRef = Dummy11;
dummyRef = Dummy12;
dummyRef = Dummy13;
dummyRef = Dummy14;
dummyRef = Dummy15;
dummyRef = Dummy16;
dummyRef = Dummy17;
dummyRef = Dummy18;
dummyRef = Dummy19;
}

/**
* a quick way for JS to check that AmfCaller is properly loaded and avaliable
* */
public function isAlive():Boolean{
return true;
}
/**
* make an AMF call
* */
public function call(url:String, command:String, parameters:Array):void{
var netConnection:NetConnection = new NetConnection();
netConnection.connect(url);
var callArgs:Array = new Array(command, new Responder(resultHandler, resultHandler));
for each(var param:* in parameters){
callArgs.push(convertObjectUsingExplicitType(param));

}
netConnection.call.apply(netConnection, callArgs);
}

/**
* callback used both for error and success. calls onResult in JS.
* */
private function resultHandler(obj:Object):void{

ExternalInterface.call(&quot;onResult&quot;, obj);

}

/**
* replaces an object marked with _explicitType by a Dummy class, and registers the Dummy class with an alias set to _explicitType.
* Yes this is absolutely bending over backwards, and is limited to 20 different explicit types.
* A possible way to override this would be to manipulate the byte code directly but it&#039;s more trouble than it&#039;s worth.
* Any suggestion on how to do this in a cleaner fashion is welcome.
* */
private function convertObjectUsingExplicitType(obj:*):*{
var type:String = getQualifiedClassName(obj);
if((type != &quot;Array&quot;) &amp;amp;&amp;amp; (type != &quot;Object&quot;)){
return obj;
}

var explicitType:String = obj[&quot;_explicitType&quot;];
if(!explicitType){
return obj;
}

//if we&#039;re here it means that the object needs to be replaced with one with which we can call registerClassAlias
//so replace by a typed one
var dummyClass:Class = null;

if(!type2Class[explicitType]){
dummyClass = getDefinitionByName(&quot;Dummy&quot; + numUsedDummyClasses) as Class;
type2Class[explicitType] = dummyClass;
numUsedDummyClasses++;
}else{
dummyClass = type2Class[explicitType];
}
var ret:Object = new dummyClass();
registerClassAlias(explicitType, dummyClass);

for(var key:String in obj){
if(key == &quot;_explicitType&quot;){
continue;
}
var subObj:* = obj[key];

ret[key] = convertObjectUsingExplicitType(subObj);
}

return ret;
}

}

}

</pre>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2013/10/31/hacking-amf-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AmfPHP 2.2 Teaser #1 Putting your code comments to good use.</title>
		<link>http://arielsommeria.com/blog/2013/10/11/amfphp-2-2-teaser-1-putting-your-code-comments-to-good-use/</link>
		<comments>http://arielsommeria.com/blog/2013/10/11/amfphp-2-2-teaser-1-putting-your-code-comments-to-good-use/#comments</comments>
		<pubDate>Fri, 11 Oct 2013 09:42:15 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=397</guid>
		<description><![CDATA[I&#8217;ve put in quite some time in working on the next version of AmfPHP. Rather than just working in isolation and just posting when the final version is ready, I thought it would be useful to give access to preview version. Hence the first &#8220;teaser&#8221;: http://www.silexlabs.org/179725/the-blog/amfphp-2-2-teaser-1-putting-your-code-comments-to-good-use/ Please give it a try!]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve put in quite some time in working on the next version of AmfPHP. Rather than just working in isolation and just posting when the final version is ready, I thought it would be useful to give access to preview version. Hence the first &#8220;teaser&#8221;:</p>
<p><a href="http://www.silexlabs.org/179725/the-blog/amfphp-2-2-teaser-1-putting-your-code-comments-to-good-use/">http://www.silexlabs.org/179725/the-blog/amfphp-2-2-teaser-1-putting-your-code-comments-to-good-use/</a></p>
<p>Please give it a try!</p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2013/10/11/amfphp-2-2-teaser-1-putting-your-code-comments-to-good-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pros and Cons of AMF</title>
		<link>http://arielsommeria.com/blog/2013/07/01/pros-and-cons-of-amf/</link>
		<comments>http://arielsommeria.com/blog/2013/07/01/pros-and-cons-of-amf/#comments</comments>
		<pubDate>Mon, 01 Jul 2013 21:04:59 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=394</guid>
		<description><![CDATA[I just posted an article about the pros and cons of using AMF http://www.baguetteamf.com/documentation/why-amf/ Obviously you&#8217;re advised to use Baguette AMF at the end, but I&#8217;ve tried to keep things factual, informative, and accessible.]]></description>
				<content:encoded><![CDATA[<p>I just posted an article about the pros and cons of using AMF <a href="http://www.baguetteamf.com/documentation/why-amf/">http://www.baguetteamf.com/documentation/why-amf/ </a></p>
<p>Obviously you&#8217;re advised to use Baguette AMF at the end, but I&#8217;ve tried to keep things factual, informative, and accessible.</p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2013/07/01/pros-and-cons-of-amf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Baguette AMF Public Beta</title>
		<link>http://arielsommeria.com/blog/2013/03/07/baguette-amf-public-beta/</link>
		<comments>http://arielsommeria.com/blog/2013/03/07/baguette-amf-public-beta/#comments</comments>
		<pubDate>Thu, 07 Mar 2013 10:57:40 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=376</guid>
		<description><![CDATA[The AmfPHP community has repeatedly asked for a performance boosting PHP extension. My answer to these requests was to create Baguette AMF. AMF is a very compact binary format, useful for transferring large amounts of complex data. It is however very demanding for a server. AmfPHP on its own does a good job, but it [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="text-align: left;">The AmfPHP community has <a href="http://www.silexlabs.org/133635/the-blog/lets-make-amfphp-faster/">repeatedly asked </a>for a performance boosting PHP extension.</p>
<p style="text-align: left;">My answer to these requests was to create <a href="http://baguetteamf.com/">Baguette AMF</a>.</p>
<p style="text-align: left;"><a href="http://en.wikipedia.org/wiki/Action_Message_Format">AMF </a>is a very compact binary format, useful for transferring large  amounts of complex data. It is however very demanding for a server. <a href="http://silexlabs.org/amfphp/"> AmfPHP </a>on its own does a good job, but it takes time, as it is <a href="http://en.wikipedia.org/wiki/Php">written in PHP</a>. Baguette AMF <a href="http://en.wikipedia.org/wiki/C_%28programming_language%29">uses C</a>, and therefore enjoys native performance. Install it on your server and enjoy <strong>up to 20 times faster conversion times</strong>.</p>
<p style="text-align: left;">
<p style="text-align: left;">It&#8217;s been in private beta for a few months, and I haven&#8217;t communicated much about it. <strong>It&#8217;s finally in public beta</strong>, so the time has come to get the word out.</p>
<p style="text-align: left;">Below is a performance chart, comparing server performance with and without Baguette AMF. Notice that for small amounts of data,  Baguette AMF doesn’t make much  difference. However when transferring  large amounts of data, using  Baguette AMF can make a huge difference in  server performance and  response times.</p>
<p><img class="aligncenter" title="performance chart" src="http://arielsommeria.com/blog/wp-content/uploads/performance-chart1.png" alt="" width="782" height="438" /></p>
<p><strong>With Baguette AMF you can now enjoy both the low bandwidth of AMF and the server performance you need for your applications.</strong></p>
<p><strong>So please try it out!</strong></p>
<p><a href="http://www.baguetteamf.com/">http://www.baguetteamf.com/</a></p>
<p>Please note that this is a commercial project and therefore not directly associated with <a href="http://silexlabs.org/">Silex Labs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2013/03/07/baguette-amf-public-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AmfPHP 2.1.1 Released</title>
		<link>http://arielsommeria.com/blog/2013/02/05/amfphp-2-1-1-released/</link>
		<comments>http://arielsommeria.com/blog/2013/02/05/amfphp-2-1-1-released/#comments</comments>
		<pubDate>Tue, 05 Feb 2013 12:42:48 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=372</guid>
		<description><![CDATA[It&#8217;s AmfPHP release time! get the latest and greatest here http://www.silexlabs.org/137222/the-blog/amfphp-2-1-1-released/]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s AmfPHP release time! get the latest and greatest here <a href="http://www.silexlabs.org/137222/the-blog/amfphp-2-1-1-released/">http://www.silexlabs.org/137222/the-blog/amfphp-2-1-1-released/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2013/02/05/amfphp-2-1-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Debug Environment for PHP Extensions on OSX</title>
		<link>http://arielsommeria.com/blog/2012/10/30/building-a-debug-environment-for-php-extensions-on-osx/</link>
		<comments>http://arielsommeria.com/blog/2012/10/30/building-a-debug-environment-for-php-extensions-on-osx/#comments</comments>
		<pubDate>Tue, 30 Oct 2012 09:38:26 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=360</guid>
		<description><![CDATA[Update: added mod_rewrite to apache config. While working on Baguette AMF, the beta testers and myself have run into the dreaded &#8216;segmentation fault (11)&#8217; error. By default, you won&#8217;t get any information in your logs about what happened and you will be powerless to fix the problem. The aim of this post is to explain [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Update: added mod_rewrite to apache config.</p>
<p>While working on <a href="http://www.baguetteamf.com">Baguette AMF</a>, the beta testers and myself have run into the dreaded &#8216;<a href="http://stackoverflow.com/questions/8843300/segmentation-fault-in-apache2-module">segmentation</a> <a href="http://www.webhostingtalk.com/showthread.php?t=950165">fault</a> (<a href="http://www.omh.cc/blog/2008/mar/6/fixing-apache-segmentation-faults-caused-php/">11</a>)&#8217; error. By default, you won&#8217;t get any information in your logs about what happened and you will be powerless to fix the problem. The aim of this post is to explain to you how to be able to use <a href="http://www.gnu.org/software/gdb/">GDB, the GNU (command line) debugger</a> to get a <a href="http://en.wikipedia.org/wiki/Stack_trace">stack trace</a> that will help you find where your code is failing. Once you&#8217;re there, you can also do what you can usually do with a debugger, such as step through the code, get variable values etc.</p>
<p>So, there are various ways to do this, but what I&#8217;ve found works for me is rebuilding debug versions of Apache, PHP, and my extension.</p>
<h1>Before we Start</h1>
<ul>
<li>Please note that this is not for the faint of heart, that it will require quite some time and patience, and that this tutorial assumes that you know quite a bit about programming, compiling etc. If you have trouble, please comment and I will try to add any missing info.</li>
<li> You&#8217;ll need <strong>root</strong> <strong>access</strong> to your server and the source code for Apache, PHP and the extension you want to debug.</li>
<li>You will need quite a few libraries installed to be able to build Apache and PHP. If you&#8217;re on a Mac like myself, I&#8217;ve  found the simplest is to use <a href="http://www.macports.org/install.php">MacPorts</a> to install Apache and PHP, and it will install all the dependencies for you.</li>
</ul>
<p><a href="http://2tbsp.com/content/install_apache_2_and_php_5_macports">There are quite a few tutorials out there on the question</a>, but here is the command line anyway. Obviously, install Macports first.</p>
<pre class="brush: php">

sudo port install php5 +apache2 +mysql5 +pear

</pre>
<p>Make sure you have a working Apache+PHP5. If you do, it means all the libraries are installed and you can get started for real.</p>
<ul>
<li>You&#8217;ll also need developer tools such as the GCC compiler. I&#8217;ve found the simplest way to get them is to<a href="https://developer.apple.com/xcode/"> install XCode</a>.</li>
</ul>
<p><span id="more-360"></span></p>
<h1>Building Apache for Debugging</h1>
<p>First, download and unzip the <a href="http://httpd.apache.org/download.cgi#apache22">Apache Source Code</a>. Note that I&#8217;ve pointed you to version 2.2. PHP 5.2 and earlier won&#8217;t build with 2.4 so it&#8217;s important to get the right version.</p>
<p>open a terminal and go to the source code folder. Then:</p>
<pre class="brush: php">

sudo ./configure CFLAGS=-g --prefix=/usr/local/apache2 --enable_rewrite

</pre>
<p>./<a href="http://en.wikipedia.org/wiki/Configure_script">configure</a> is a script that prepares the way so that the &#8216;make&#8217; script afterwards can work on your system. I&#8217;ve added three options that need explaining:</p>
<ul>
<li><em>CFLAGS=-g</em> tells the compiler to add debug symbols, as <a href="http://httpd.apache.org/dev/debugging.html">described here</a>.</li>
<li><em>&#8211;prefix=/usr/local/apache2 </em>tells the configure script where apache must look for its configuration file. When you install your new apache, its files will be written to /usr/local/apache2. If you don&#8217;t set this, it will read its configuration from /etc/local/apache2.</li>
<li><em>&#8211;enable_rewrite=shared </em>This adds mod_rewrite as a shared module. Not strictly necessary, but if you want to use your Apache with any modern web package then you&#8217;ll probably need mod_rewrite.</li>
</ul>
<p>Then, if your configuration went well:</p>
<pre class="brush: php">

sudo make clean all install

</pre>
<p>This executes the &#8216;clean&#8217;, &#8216;all&#8217; and &#8216;install&#8217; commands in the makefile.</p>
<ul>
<li>Clean gets rid of any intermediate compiled files. It&#8217;s not necessary unless you are having trouble building. But I find it&#8217;s good practice to include it just in case. Otherwise it&#8217;s happened that I see some meaningless error messages that could be solved with a clean.</li>
<li>all is the actual compilation.</li>
<li>install does the actual installation, ie writing the various files to your system, mostly in /usr/local/apache2.</li>
</ul>
<p>If all went well, you can then run this to start your new Apache. Make sure the port you are using (usually 80) is not used before.</p>
<pre class="brush: php">

sudo /usr/local/apache2/bin/apachectl start

</pre>
<p>and open your browser, point it to &#8216;localhost&#8217;, and normally you should see &#8216;It Works&#8217; in your browser.</p>
<p>It works? Good! Onto PHP then.</p>
<h1>Building PHP for Debugging</h1>
<p>To build PHP I recommend using <a href="http://cweiske.de/tagebuch/Introducing%20phpfarm.htm">PHPFarm</a>. It will allow you to switch easily from one PHP version to another. Please note that sometimes the PHP version you want doesn&#8217;t build. The simplest is to try with another version. There&#8217;s some good extra info on how to use <a href="http://dbforch.wordpress.com/2010/05/21/apache2-fastcgi-multiple-php-versions-ubuntulucid-10-04/">PHPFarm here</a>. PHPFarm messes up the paths slightly for the CLI version of PHP on Macs, but that shouldn&#8217;t stop you from using it.</p>
<p>So first build the CLI version of PHP as described in the links above. Then you can move onto to a debug version built for Apache.</p>
<p>My configuration options for building PHP 5.3 are the following:</p>
<pre class="brush: php">

configoptions=&quot;
--with-apxs2=/usr/local/apache2/bin/apxs 
--prefix=/usr/local/apache2/php 
--without-iconv

&quot;

</pre>
<p>The first 2 tell the script to build for apache and where to put the files. The bit about iconv is because I had trouble building with iconv.</p>
<p>If all went well, you can configure Apache to use PHP. Add the following to your Apache config, and restart it.</p>
<pre class="brush: php">

LoadModule php5_module        modules/libphp5.so
AddHandler php5-script    .php
AddType application/x-httpd-php .php

#just add the index.php bit, as the DirectoryIndex bit is already there

DirectoryIndex index.html index.php

</pre>
<p>Now test that you can run some PHP code. Good? On to the PHP extension&#8230;</p>
<h1>Building your extension</h1>
<p>If you got to here, building your extension shouldn&#8217;t be too much of an issue. Here&#8217;s a typical script:</p>
<pre class="brush: php">

/php-5.3.2/bin/phpize
./configure --with-php-config=/php-5.3.2/bin/php-config
make clean all

</pre>
<p>Then make sure in your php.ini that your extension is loaded, check that it actually loads with phpinfo, and try to reproduce that segmentation fault!</p>
<p>Got it? Good. Now onto Debugging&#8230;</p>
<h1>Getting a stack trace with GDB</h1>
<p>In our case we want to run apache+PHP+ our extension, attach GDB to the process that will crash, provoke the crash, and gather whatever info we need to fix the issue.</p>
<p>The thing is, apache has multiple processes. So it&#8217;s difficult to know what process is going to crash. The simplest thing to do is to make sure it only runs one child process. So, add this to your apache config:</p>
<pre class="brush: php">

MaxClients 1

</pre>
<p>Then you can just run ps or look in the Activity Monitor to get the process number.</p>
<p>Once you can reliably predict which process is going to crash, run the following line(replace 1234 with the relevant process id):</p>
<pre class="brush: php">

sudo gdb /usr/local/apache2/bin/httpd 1234

</pre>
<p>This runs gdb on the apache executable, and tells it to attach to the process 1234.</p>
<p>Now make Apache crash!</p>
<p>in gdb type &#8216;bt&#8217; and you should get a stack trace telling you where your extension&#8217;s code failed.</p>
<p>Note: if you don&#8217;t see your extension&#8217;s code mentioned in the trace, try &#8216;continue&#8217; then &#8216;bt&#8217; again.</p>
<p>There you are. Hope that helps, and good luck with debugging!!</p>
<h1>Further Reading</h1>
<p>Some links that I&#8217;ve found helpful:</p>
<p><a href="http://dan.drydog.com/apache2php.html">http://dan.drydog.com/apache2php.html</a></p>
<p><a href="http://2tbsp.com/content/install_apache_2_and_php_5_macports">http://2tbsp.com/content/install_apache_2_and_php_5_macports</a></p>
<p><a href="http://www.viraj.org/b2evolution/blogs/index.php/2005/09/15/the_art_of_debugging_apache_segfaults">http://www.viraj.org/b2evolution/blogs/index.php/2005/09/15/the_art_of_debugging_apache_segfaults</a></p>
<p><a href="http://httpd.apache.org/dev/debugging.html">http://httpd.apache.org/dev/debugging.html</a></p>
<p><a href="http://xerces.apache.org/xerces-c/build-3.html">http://xerces.apache.org/xerces-c/build-3.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2012/10/30/building-a-debug-environment-for-php-extensions-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AmfPHP survives Zend AMF</title>
		<link>http://arielsommeria.com/blog/2012/10/17/amfphp-survives-zend-amf/</link>
		<comments>http://arielsommeria.com/blog/2012/10/17/amfphp-survives-zend-amf/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 11:30:44 +0000</pubDate>
		<dc:creator><![CDATA[Ariel]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://arielsommeria.com/blog/?p=357</guid>
		<description><![CDATA[Zend AMF smells funny, whereas AmfPHP is doing well. What happened? http://www.silexlabs.org/136374/the-blog/amfphp-survives-zend-amf/]]></description>
				<content:encoded><![CDATA[<p>Zend AMF smells funny, whereas AmfPHP is doing well. What happened?</p>
<p><a href="http://www.silexlabs.org/136374/the-blog/amfphp-survives-zend-amf/">http://www.silexlabs.org/136374/the-blog/amfphp-survives-zend-amf/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://arielsommeria.com/blog/2012/10/17/amfphp-survives-zend-amf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
