Thursday, April 28, 2011

Nginx: Running FastCGI Under an Alias

So yay, Nginx has been a new playground for me here. It's awesome thus far and I love the process management! I've still got a bunch of exploring to do and I'm super busy, so excuse the brevity!


FastCGI Issues With Aliases

I've scoured the web for help on this one and it seems like a common issue that people have had. Check out the comment section on this post for a good starting point on this issue. But the usual trial and error was what ultimately got everything working for me.


Here's what I got working for me below:

location /dir/ {
alias /usr/local/www/foo/;
index index.php;
}

location ~ /dir/.*\.php$ {
if ($fastcgi_script_name ~ /dir(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/foo$valid_fastcgi_script_name;
include fastcgi_params;
}


The problem I was running into was here:
location ~ /dir/.*\.php$ {
if ($fastcgi_script_name ~ /dir(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}

I assumed $fastcgi_script_name was going to be from /foo but it was already being passed the alias (/dir).


I suppose I'm just writing this to remind me in the future, but in case this helps anyone else, hope it makes sense!


Cheers!

Tuesday, April 12, 2011

PHP: Encode Text Into Numeric HTML Entities While Keeping HTML

If for whatever reason you need to have some text with special characters encoded into numeric HTML entities, but you also have HTML that you do not want to encode, well here you have it!


Why Numeric HTML Entities?

If you've worked with RSS before I'm sure you understand the dilemma. For those of you that don't know, RSS has a problem with validating if there are non-numeric HTML entities (the normal output you get from htmlentities()). More headaches, more XML fun!


Why Keep HTML?

Well, to be honest, it's just because we have a special scenario right now. But, I'm sure some people may find this helpful.



*Note* The numeric HTML entities foreach loop is based off of Michael Krenz's xml_character_encode function. Thank you sir!


function htmlentities_keephtml($text) {
$entities = get_html_translation_table(HTML_ENTITIES);
unset($entities['"']);
unset($entities['<']); unset($entities['>']);
unset($entities['&']);
foreach ($entities as $k=>$v)
$entities[$k] = "&#" . ord($k) . ";";
$s = array_keys($entities);
$r = array_values($entities);

$text = html_entity_decode($text, ENT_NOQUOTES); // decode the named entities
$text = str_replace($s, $r, $text); // now encode to numeric entities

return $text;
}

Saturday, April 9, 2011

Amazon Cloud Drive Now Doesn't Support Multiple Downloads?!


Wait, what?!

This change must be recent because I downloaded the only two albums I purchased from Amazon already and I definitely did NOT download them one at a time. I just so happen to have downloaded those files on my laptop and now I'm on my desktop. Yes, I can simply power on my laptop, but what's the point of having my files in the Amazon Cloud Drive anyway then?!


So now, 99 files for me to download one at a time?! (Yes, that's right classical music!) Not cool Amazon. Fail on you...


Update: Okay, between sometime after this post and now (April 19, 2011), Amazon has made multiple downloads possible again. Thank you Amazon!

Thursday, April 7, 2011