Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Mac OS X launchd plist to run PHP fcgi

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version='1.0'>
	<dict>
	<key>Label</key><string>com.automatthew.php</string>
	<key>ProgramArguments</key>
	<array>
	        <string>/opt/php/bin/php</string>
	        <string>-b 127.0.0.1:9000</string>
	        <string>-q</string>
	</array>
	<key>EnvironmentVariables</key>
	<dict>
	        <key>PHP_FCGI_CHILDREN</key>
	        <string>4</string>
	</dict>
	<key>Debug</key><false/>
	<key>Disabled</key><false/>
	<key>OnDemand</key><false/>
	<key>RunAtLoad</key><false/>
</dict>
</plist>

running multiple domains off a single rails app with different page caching directories

Problem: You have multiple instances of a rails app that use page caching, but you'd rather not set up a separate instance for each one.

Lighttpd config:
#... normal lighty conf...
server.document-root = "/home/rails/app/public/"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = (
  ".fcgi" =>
    ("localhost" =>
      (
       "min-procs" => 1,
       "max-procs" => 1,
       "socket" => "/tmp/rails-fcgi1.socket",
       "bin-path" => "/home/rails/app/public/dispatch.fcgi",
       "bin-environment" => (
         "RAILS_ENV" => "production",
         "TZ"        => "America/Chicago"
       )
     )
    )
 )

$HTTP["host"] =~ "site1.net" {
  server.document-root = "/home/rails/app/public/site1.net"
}
$HTTP["host"] =~ "site2.net" {
  server.document-root = "/home/rails/app/public/site2.net"
}


Rails code to set the page cache directory:

before_filter { |c| c.class.page_cache_directory = "#{RAILS_ROOT}/public/#{c.request.host}" }


Remember to symlink your necessary files AND your dispatch.fcgi to each page cache directory.

manual reaping of fcgi processes

These are the signals that SwitchTower's reaper uses:

# reload
kill -s HUP @pid

# graceful
kill -s TERM @pid

# kill
kill -9 @pid

# usr1
kill -s USR1 @pid

Install fcgi gem after installing FastCGI with darwinports

sudo gem install fcgi -- --with-fcgi-dir=/opt/local

FastCGI test script

If you're having trouble with FastCGI (as I was), this Perl script can help you see if the problem is at the Apache end or the app end. In my case I'd simply not deleted the old Ruby sessions for my Rails app when switching from CGI to FCGI ;-) This script proved my Apache wasn't broken, at least.

#!/usr/bin/perl

use FCGI;

$cnt = 0;

while (FCGI::accept() >= 0)
{
   print ("Content-type: text/html\r\n\r\n");
   print ("<head>\n<title>FastCGI Demo Page (perl)</title>\n</head>\n");
   print  ("<h1>FastCGI Demo Page (perl)</h1>\n");
   print ("This is coming from a FastCGI server.\n<BR>\n");
   print ("Running on <EM>$ENV{USER}</EM> to <EM>$ENV{REMOTE_HOST}</EM>\n<BR>\n");
    $cnt++;
   print ("This is connection number $cnt\n");
}
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS