php exception handling on iis 7

June 10th, 2009

I was recently deploying a PHP site to a client hosting their content with IIS 7. In my code, I typically raise and handle exceptions. My philosophy is simply that exceptions are logical operators like “if”, “then” and “while”. At any rate, when I deployed this code to the production environment, IIS would raise an HTTP 500 exception. This is not ideal.

After hours of desperate searching, I finally found the solution to appropriate exception handling with php on IIS on the iis blog. The solution was more of a footnote about halfway down the page in the php.ini section. The trick is to set fastcgi logging to false. Not the most ideal solution, but I was finally able to handle exceptions the way php code should.

From iis blog: “FastCGI logging should be disabled on IIS. If it is left enabled, then any messages of any class are treated by FastCGI as error conditions which will cause IIS to generate an HTTP 500 exception.”

php.ini

fastcgi.logging = 0 ;

Stuff I'm Working On, web , ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Improved Content Slider In MooTools

May 27th, 2009

A little while ago, I posted some javascript for a mootools content slider. I’ve used it a lot in my own Ruby on Rails and PHP development work and my work with jv2 I have been itching to just drop it into my code like Squeezebox or Swfobject.

So, here it is, a fairly beta version of a horizontal content slider written with the Mootools 1.2 framework. Simply download (or copy and paste) the ContentSlider class into your page and then instantiate with the required arguments.

Read more…

HowTo, Stuff I'm Working On , ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Web 2.0 on a Plane

March 10th, 2009

Kevin Rose, founder at Digg.com was flying from SFO to New York city this morning when he connected to Virgin America’s on board wi-fi connection and began streaming his trip from 30,000 feet.

Utilizing twitter, he sent out a tweet with a link to where people could view his stream. Interacting with the audience of over 700, he gave a quick tour of the plane from his seat, showed his viewers his neighbor and the view from his window.

A very cool interactive experience which shows that the Internet is becoming more ubiquitous all the time.

Kevin Rose U-Streams from a plane

had to share, technology

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Mootools content slider - javascript

March 5th, 2009

This is an old version of an improved Mootools Content Slider

I recently implemented a javascript based slider using MooTools. I’m increasingly becoming a huge fan of Mootools. Their documentation is great and the code I write just seems to be much cleaner. I don’t feel like it’s as fragile as js I’ve written in prototype/scriptaculous.

The content slider, which I pretty much implemented verbatim using Antonio Lupetti’s great tutorial at http://woork.blogspot.com/2009/01/elegant-animated-weekly-timeline-for.html.

Antonio’s tutorial is really great. It is missing two elements which I think improve the code base: Read more…

Stuff I'm Working On , , ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Is Facebook Oppressing the Irish?

February 19th, 2009

I write Facebook applications. It’s part of my job. When I show them off to customers, I’m a little uncomfortable adding them as a friend. They don’t need to see the crazy shenanigans of my friends and me. I signed up for my “private” version of Facebook this morning and learned that Facebook officially restricts the Irish.

Facebook hates the Irish

I mean, who else has more than one capital letter in their name?

had to share

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Tough Day For Microsoft

January 2nd, 2009

More information can be found at the links provided, but Microsoft is not starting the year off strong. Most media outlets led with a story about how the Zune, Microsoft’s digital music player, was hit with a glitch in how its internal clock accounts for leap year. Then, it’s industry leading web browser, Internet Explorer, lost some major market share. An unfortunate start to 2009 for Microsoft.

Zune article: http://bits.blogs.nytimes.com/2008/12/31/the-day-microsoft-zunes-stood-still/

IE losing market share: http://online.wsj.com/article/SB123092719894149695.html#articleTabs%3Dcomments

 

 

business/entrepreneurship, had to share, technology ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

A Bail Out Plan That Might Actually Work

January 2nd, 2009

Autos, banks and investment firms have all benefited this year from a plethora of legislative handouts. The firms receiving our hard-earned tax dollars have all been publicly traded and have several thousand employees. More money has been set aside and spent in the last two months for distressed banks and brokers than the Iraq war has racked up in the last seven years.

I don’t particularly agree with the bailout of the auto industry. Sure I have some nostalgic love for Ford, GM and Chrysler, but my beef is that we the people are supporting a broken business model that is destined to fail even after our taxes prolong the inevitable death. After reading this article in the Wall Street Journal (as well as a few other articles) I’m willing to pronounce that one of the most efficient uses of government bailout dollars, outside the banking system, is to provide short term financing to small businesses.

What’s the Real Problem?

The real problem is not necessarily a lack of customers or progress. Mainly, it’s a short term cash problem. Business A is waiting on their accounts receivables to come in so they can pay their bills to Business B. Business B is waiting on A so they can pay C. The phenomenon continues in this cascade of capital lockup.

Businesses are largely not reporting crippling sales declines or other top line dangers. Small businesses are also some of the most efficient companies in the world so their bottom lines cannot get much leaner. They’re also the types that capital freezes affect the most.  The true problem is the working capital needed to sustain their operations while the A/R - A/P cascade (above) continues.

Can The Business Models Survive?

My beef with the auto industry bailout is that the business model has been in trouble for a long time. Honda, Toyota and Kia, to name a few, have solid businesses that are using US labor and moving the cars out of the showrooms into our garages. The Big Three have labor costs that are way out of whack with the actual value the labor provides the business. Further, innovation from the Big Three has been limited in comparison to foreign auto makers.

Tangentially, saving Chevy based on the promise of the Volt is a risky bet. It would be best served by spinning the Volt off into its own company and then pursuing venture capital to execute that new business model. Venture capitalists have the stomach and smarts to fund companies with millions of dollars based on the promise that a business model will emerge when the product goes to market. Venture capital is not necessarily a responsible use of our tax dollars.

But I digress. The main point that should be made is that the business models of the Big Three auto makers is antiquated and insolvent in any economy, especially a tough one.

The Government Should Fund Robust Business Models

Banks are pulling small business lines of credit because of their own tight cash flows. This is a major contribution to the crunch on cash flow of the small business. If the government is to rescue any industry, it has the responsibility to invest wisely in businesses that will be around in a year to repay their bailout either as a loan or as a contribution to a growing economy.

Small businesses, taken as a whole, are on a growth path and are limited by short term working capital. Loaning this working capital at reasonable interest rates not only ensures these businesses survive, it is also a more diversified and responsible investment.

Small businesses are 99.7% of all private enterprises in America and employ 50% of all private sector employees (source). Rather than focusing billions of dollars on failing business models that support a fraction of American labor, I propose a more diversified, responsible investment into companies that represent the sweat and tears of America’s gutsiest.

Uncategorized, business/entrepreneurship

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Backing Up Data To Git Securely: Part-1 - Create the Database User

December 24th, 2008

In my backup script I previously posted, we begin by dumping the entire contents of the database to a file. This is not necessarily a good idea and there may be better ways to backup your data. However, the total size of my database is only a few MBs so it isn’t worth the hassle of creating a master-slave setup.

The goal is to dump the database to the filesystem, add it to the tar file, encrypt it and then delete the clear text version of the file.

Security considerations abound. In a nutshell however, it is important not to publish any unencrypted database dump anywhere. Dump files can be searched on easily by Google and if you house even a morsel of private user data, you’ll be in trouble very quickly if it’s not encrypted.

Getting started, the MySQL command to dump a database is:

 mysqldump -u user -psupersecret --all-databases > /some/dir/backupsql.sql

-p will prompt for a password

-all-databases will dump every database you have running on the mysql instance. If you want a specific database, replace –all-databases with your_db_name

This command pushes the output of the mysqldump command to a file on the filesystem.

Since I don’t want my cron job to be prompted for a user’s password when dumping the db, I have created a special backup user with only enough permissions to read the tables, and write their contents to a file. You can create such a user by running the following command inside a mysql prompt:

GRANT SELECT, LOCK TABLES ON *.* TO 'backup'@'localhost'
IDENTIFIED BY 'supersecret'

Make sure to flush privileges after creating users. There’s not much more frusterating than trying to figure out why that script didn’t work.

One security consideration is that if you were to run the ps command while the dump script is running, it will expose the username and password of the backup user potentially allowing other users of the system to make select statements to databases they otherwise shouldn’t be on.

By limiting the backup user access only from the localhost, this eliminates the possibility of someone else dumping your database from some other host; the user must be logged into the box the database resides on.

At the conclusion of this script, we will have all the database data and structure backed up to a file on the filesystem. In the next post, I’ll explain how to add this data to a tar archive and then encrypt the whole mess.

HowTo, Stuff I'm Working On ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

HOWTO: Securely Backup Your Data Offsite Using Git, OpenSSL and Basic Linux Commands

December 21st, 2008

I am becoming a better systems administrator every day secondary to my work as a ruby on rails and PHP developer. As a very small development shop I have very limited resources to perform the backup and recovery policies bigger shops and huge enterprises employ.

However, after just a morning of futzing with a few key linux commands and better utilizing a service I already back up my source code to (www.github.com) I have a found a robust and secure way to handle automated, off-site, redundant backups in a way that will let me compete with some bigger shops. I’ve posted the code below so I hope you will find it useful. Over the next few posts, I’ll unpack what I’ve written and the philosophy behind it.

A few things bothered me in the way I was doing traditional backups:

  1. I knew I had to get them off-site, but actually finding time to get off-site (to a secure location) wasn’t happening.
  2. The backup had to be absolutely secure. My clients’ source code is too precious and leakage too damaging to make even one mistake with security breach
  3. Had to be simple and automated. I usually have 10 other things I need to do at the same time. I didn’t want backups to be number 11.
  4. Small file size. Again, being a small dev shop, I didn’t want to put a lot of cost into storage of incremental backups
  5. Incremental backups were key since I don’t want to go to all this trouble only to restore a copy of the bad data I was trying to replace. If I a problem isn’t made known until after the next set of backups are made, I’d be overwriting bad data with bad data; better to restore to the point before the problem happened.
 
 
#!/usr/bin/sh
 
#backupdb
echo "======================================"
echo "backing up database"
mysqldump -u backup --all-databases > /var/www/html/alldatabases.sql
 
#tar and compress the directories really hacky and should either make a file for exclusions or just get rid of the crap
tar -czvvf /var/www/bkp/websqlbkp.tar.gz /var/www/html/alldatabases.sql /var/www/html/*
 
#encrypt that mug and then remove the decrypted file
echo "encrypting backup"
openssl des3 -salt -k supersecret \
        -in /var/www/bkp/websqlbkp.tar.gz \
        -out /var/www/bkp/websqlbkpencrypted.tar.gz
 
#cleanup files I don't want people to see
echo "cleaning up files"
rm -rf /var/www/bkp/websqlbkp.tar.gz
rm -rf /var/www/html/alldatabasesl.sql
 
#update the git repo
echo "committing to git `date` "
cd /var/www/bkp/
 
echo "adding to git"
/usr/local/bin/git add .
 
echo "commiting git"
/usr/local/bin/git commit -a -m "commiting backup on `date`"
 
echo "pushing to github"
/usr/local/bin/git push origin production

How-To, HowTo, Stuff I'm Working On ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com

Linux Suitable For Consumer?

December 17th, 2008

I recently read this article at FastCompany’s website about Linux: the open source, freely available operating system. While it technically competes with Windows and Mac OS X, most users have probably never heard of it. Most data center admins probably couldn’t live without it. It has a commanding lead in the enterprise hosting space and is responsible for hosting most of the websites on the Internet today. This website, for example, is hosted on a Linux box somewhere in Texas.

The article was profound in explaining Linux’s potential power play in the netbook arena; netbooks are small low power laptops. They’re great for surfing the web, doing emails and many other normal, everyday, tasks. Their low power makes them very affordable but has a major shortcoming when it comes to loading an operating system. Without a lot of memory (Ram) or hard drive space, large operating systems with many background processes would cripple the tiny netbook and render them useless.

Enter Linux. Linux is a highly configurable dream of an operating system that technologists love to play with. Because of its configurability, it’s a perfect candidate to run on a netbook. Processes that are never used can be shut off automatically. Shutting down processes means 1) more memory to do web surfing 2) more processor cycles for web surfing and 3) less space taken up on the hard drive.

Another very important consideration is spyware/malware. Linux is a very secure system by its very nature. The kernel (the brains of the OS) is more protected by its very design. Because of its seemingly insignificant market penetration, spammers and malware developers don’t have any incentive to develop their bugs for this OS. Linux wins again.

Finally, slapping Linux on the netbook follows a bigger trend in the commodization of hardware. Computers are getting cheaper and cheaper as business processes become more efficient and components become less expensive. The operating system has become a bigger slice of the total purchase price of a system. As hardware continues to become more of a commodity, vendors like IBM, HP and DELL will look for ways to jettison the proportionately higher cost of the OS.

As netbooks become more popular, Linux will become more familiar. This familiarity will enhance a seemingly insignificant player in the consumer operating system battle and that could really change the game.

original link:

http://www.fastcompany.com/blog/chris-dannen/techwatch/2009-year-linux-revolution

business/entrepreneurship, technology , ,

Bryce McDonnell is a Ruby on Rails and PHP web applications developer in Portland, Oregon. Learn More about his company, sites and get online marketing help at brycemcdonnell.com