<?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>Game Haxe &#187; cgi</title>
	<atom:link href="http://gamehaxe.com/tag/cgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://gamehaxe.com</link>
	<description>Experimenting with Web Game Development</description>
	<lastBuildDate>Fri, 17 Jun 2011 01:24:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>FastCGI For Neko On Share Hosting</title>
		<link>http://gamehaxe.com/2009/12/04/fastcgi-for-neko-on-share-hosting/</link>
		<comments>http://gamehaxe.com/2009/12/04/fastcgi-for-neko-on-share-hosting/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 08:05:10 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[neko]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[Haxe]]></category>
		<category><![CDATA[shared hosting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=266</guid>
		<description><![CDATA[In my previous post, I described you could setup neko web services on a shared host, using CGI. This method is not as efficient as it might be because a separate process is required for each request. However it is &#8230; <a href="http://gamehaxe.com/2009/12/04/fastcgi-for-neko-on-share-hosting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my previous post, I described you could setup neko web services on a shared host, using CGI.  This method is not as efficient as it might be because a separate process is required for each request.  However it is possible to extend this to &#8220;Fast CGI&#8221; (FGCI), which starts a single process, and keeps it alive.  Apache talks to this over a socket, sending requests and receiving data and a very efficient manner.</p>
<p>If you got CGI working, and your server supports FCGI, then the transition on pretty simple.</p>
<p>The first thing to do is to download the new &#8220;fastcgi&#8221; haxelib.  From a shell use:</p>
<pre>
haxelib install fastcgi
</pre>
<p>If haxelib asks you for a project directory, the following discussion assumes you specify your &#8220;haxeneko/lib&#8221; directory.<br />
There is one bit of housekeeping you should do at this time &#8211; copy the &#8220;nekoapi.dso&#8221; object from &#8220;~/haxeneko/lib/fastcgi/0,1/ndll/Linux&#8221; into your &#8220;~/haxeneko&#8221; directory.  This ensures that this dso will be found when neko is run by the web server.</p>
<p>Now it is time to change the cgi script.  The code is very similar, except the extension should be &#8220;.fcgi&#8221;.  Here is the script I used Site.fcgi:</p>
<p><code>
<pre>
&#35;!/bin/sh
export HAXENEKO=~/haxeneko
export LD\_LIBRARY\_PATH=$HAXENEKO
export PATH=$PATH:$HAXENEKO
export NEKOPATH=$HAXENEKO
export HAXE\_LIBRARY\_PATH=$HAXENEKO/std
cd ../../site
exec neko SiteFCGI.n
</pre>
<p></code></p>
<p>Note the final &#8220;exec&#8221; call to ensure the pipes are all correctly plumbed.<br />
And the obvious change to the .htaccess file (.fcgi extension):</p>
<p><code>
<pre>
RewriteEngine on
RewriteRule \\.(css|jpe?g|gif|png)$ - [L]
RewriteRule ^(.*)?$ cgi-bin/Site.fcgi [L]
</pre>
<p></code></p>
<p>Finally, compile the &#8220;Test.hx&#8221; file that came with the fastcgi lib.  I have a slightly altered version here:</p>
<p><code>
<pre>
class Test
{
   static var processed = 0;
   static public function main()
   {
      // Called in single threaded mode...
      fastcgi.Request.init("");
      // This can be called multi-threaded...
      var req = new fastcgi.Request();
      while( req.nextRequest() )
      {
         req.write( "Content-type: text/html\r\n" +
            "\r\n" +
            "&lt;title&gt;Neko FastCGI&lt;title/&gt;" +
            "&lt;h1&gt;Fast CGI&lt;/h1&gt; Requests processed here: " + (processed++) );
         req.write( "\n page = " + req.getParam("REQUEST\_URI") );
         req.close();
      }
   }
}
</pre>
<p></code></p>
<p>This version prints the request uri too.  To compile, use:<br />
<code><br />
haxe -main Test -neko SiteFCGI.n -lib fastcgi<br />
</code></p>
<p>And that should be that!  When you visit your web page, you should see the &#8220;processed&#8221; counter increase, verifying that it is the same process that is running.</p>
<p>Currently the system does not support easily killing the FCGI process, which is something that you must do when you update the &#8220;.n&#8221; neko file.  The only way at the moment is to use the shell to do &#8220;ps -x&#8221; to identify the process number, and then &#8220;kill -9 number&#8221;, where number is the process number of the neko executable.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2009/12/04/fastcgi-for-neko-on-share-hosting/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

