Mar
5
I was tasked with moving a CakePHP based site from Dreamhost to a Grid Server at MediaTemple, and while doing so thought it would be a good time to get the site into Git and deploy with Capistrano. Turned out to be a little bit of headache. Last night I was finally able to complete a recipe that would deploy the site to the Grid Server (gs). It required a few directory changes and symlinks put in place, but it works now. The process for deploying a Rails site to a (gs) container is pretty well documented, but deploying a non-Rails site to a domain directory on the Grid Servers is not. Hopefully this helps others. I’m not sure how common it is in the PHP world to deploy a site using Capistrano.
Aug
14
accessing external PHP Sessions in CakePHP
August 14, 2008 | 6 Comments
During a recent project, I was asked to build an extension onto a site we had done many moons ago. The original site was just custom rolled PHP. No frameworks at all. However, with the new extension I decided to use CakePHP. The extension could live standalone, but needed to be “aware” of some data from the original app. More specifically, something similar to a login sets a session var upon success. I didn’t think it would be all that big of a deal to read that Session in Cake, after all it was still PHP on the same box, in the same application name space. I was wrong.
The explanation is pretty simple to understand. Cake has it’s own Session handling. Because of this Cake creates a Session automatically by default. This can be turned off in the configs, but really isn’t the root of the problem. The issue lies in Cake not being aware of the external app’s already created Session. There are many posts about injecting data from external Sessions into a Cake Session, but that doesn’t seem very DRY to me. It could cause issues with data being out of sync as well. A lot of management could need to occur.
So last night I decided to try something relatively simple in hind sight. I wanted to figure out a way for Cake to just use the external Session. Bottomline, it’s pretty easy. All you have to do is pass the session ID (session_id()) from the external to the Cake app. Querystring param or whatever. And then in your Cake controller, set a beforeFilter method that accepts the param and uses it to create a new Session, which is already created, so Cake just uses it.
if (isset($_GET['SESSIONID'])) { session_destroy(); session_id($_GET['SESSIONID']); session_start(); }
After that, you can access any properties from the external session in Cake natively using Cake’s built in methods like:
$this->Session->read('param_name');
or just through the PHP Session Object:
$_SESSION['param_name']
Apr
14
Handling SWF Request Handlers in CakePHP
April 14, 2008 | Leave a Comment
I’m in the middle of a project that had a catalog of SWFs as content. The catalog needs to be edited/modified. I’m using CakePHP as the framework. The beta version of CakePHP 1.2 introduces something burrowed from Rails called Request Handlers. This works perfect for what I am needing to do. My SWFs are stored in a database as blobs. I am going to retrieve them using AMF (i.e. Flash Remoting). But I need a convenient way to server them, rather than digging through a filesystem. So I am going to use Request Handlers.
The idea is pretty simple. I want to be able to call a controller action something similar to /give/me/swf/number/14. So I am looking for a SWF with ID 14 in the database table. BUT, it would be cool if I could also serve up a corresponding GIF if the user doesn’t have the plugin. Request Handlers allow me to do this with little worlk. My controller can handle requests and react depending on file extension. So something like /give/me/item/index.swf?id=14 and /give/me/item/index.gif?id=14 would deliver either a SWF or a GIF depending. No extra logic in the controller needed. Pretty cool.
There are a couple of things need for this to be setup correctly in CakePHP. First you have to set the Request Handler for SWFs. This goes in the app_controller
/**
* setContent – used to setup request handler for swfs
*
* @return void
**/
function setContent()
{
$this->RequestHandler->setContent(‘swf’, ‘application/x-shockwave-flash’);
}
Next, you need to set the content in the beforeFilter of the controller that is going to react:
/**
* prior to rendering
*
* @return void
**/
public function beforeFilter()
{
$this->setContent();
}
Then in my controller action, I do something similar to:
$this->set(‘file’, $this->Symbol->findByid($this->params[‘url’][‘id’]));
This sets the data for my view, which I have to create corresponding views for extensions so I respond with the correct mime types. So if this is in a medias controller, I need /views/medias/swf/index.ctp. Inside that I set the MIME info:
<?php
// Output the MIME header
header (“Content-transfer-encoding: binaryâ€);
header (“Content-Type: application/x-shockwave-flashâ€);
header (“Content-Length: †. $file[‘Symbol’][‘size’]);
header (“Pragma: publicâ€);
header (“Expires: 0â€);
header (“Cache-Control: must-revalidate, post-check=0, pre-check=0â€);
header (“Cache-Control: privateâ€);
// Output the flv
print $file[‘Symbol’][‘file’];
?>
Hopefully I didn’t forget any pieces. I wanted to write this up right when I did it, mostly so I wouldn’t forget the steps, but unfortunately that didn’t happen. Leave comments if I forgot something.
May
29
crypto lock error when compiling PHP
May 29, 2007 | Leave a Comment
Over the weekend I needed to recompile PHP on my PowerBook and ran into the bug described here and here. Apparently, there are two conflicting libraries that PHP references during compile and the solution was to downgrade mysql to alleviate the problem. I didn’t want to downgrade, to mysql 4.1, because it would break my Rails config. So, I tried upgrading instead, to mysql 5.1. I was using 5.0.x. And the upgrade path worked.
Remember to backup your data first, then simply grab the DMG package from the mysql site. Install. Restart your computer for best practice, and then reconfig and compile PHP. You might need to wipe out the PHP source directory and untar the PHP source again. For some reason old makes don’t get cleaned out all the time. Worked for me.
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
Sep
30
Making Flash Remoting sexy
September 30, 2006 | Leave a Comment
How do you make a technology that passes binary data over the wire sexy? That has been the challenge for the development team I am on. Flash Remoting is one of those technologies that is not an easy to understand concept for business people and even some IT folks. However, they are the key holders for budgets.
So, our development staff wrote a white paper. We included the top ten reasons from Adobe (although number 10 needs to be corrected, Remoting is not available on devices – BUT SHOULD BE), but that is marketing speak and doesn’t really get down to it. When we are approaching a client like Proctor & Gamble, they want to know how it affects the bottomline. Does it mean that the site/app will be built in a shorter timeframe, etc… In a way the answser is yes.
We identified a few key areas that make Remoting sexy and figured out how to speak to these key areas in a way that the decision makers could understand.
The first was Service Oriented Architecture. Remoting enables collaboration between two teams. One on the front-end, one on the back-end. Business people understand the benefit of two teams working at the same time. It means getting applications to market faster. SOA has many many benefits. Remoting brings all of these benefits to Flash. One gateway with established methods is truly beneficial. Established methods all contained in one gateway also allows platform flexibility and maintainability.
The second is increased security. Nothing is completely secure, but at least wrapping things up in binary is much less accessible than plain text bytes. Hackers are less likely to decipher the method calls and re-write their own spoofs in AMF. For example, hacking a game to cheat on a high score is more difficult without knowing something about the Remoting protocol.
The third is debugging. Remoting provides some mature debugging features. When writing applications that require coordination between clients-side and server-side, debugging can be difficult to do in a convenient matter. Debugging in Remoting provides a consistent method allowing teams to identify bugs and fix them in a more timely fashion.
We identified other areas such as one technology to deploy across the architecture to establish a standard, but they are more specific to the existing architecture etc.
We are big fans of Remoting at Barefoot. I hope to see more done on projects such as AMFPHP and WebOrb. It seems that Remoting had dropped off for a little while out of the communities radar, but has recently seen some activitiy. I hope that trend continues.
In the end, a binary serialization/deserialization protocol may not be sexy to the powers that be, but benefits like SOA and debugging seem to be. That’s our experience. Clients really do benefit from the promotion of well-designed applications that are a result of Flash Remoting.
Aug
20
Neo -> Developer Edition
August 20, 2002 | Leave a Comment
Yesterday I decided to experiment with Cold Fusion MX again, and found out that my “NEO” version of the beta release had tried to change itself to a developer edition. In the process some file mapping got screwed up and was stopping JRUN from running correctly. The fix was a re-install. If you have a problem with CFMX just not working one day, you may have the same problem. The Developer Edition is available for free from MM’s site.