Tag Archives: software

Creating your PHP Onboarding for Windows machines

There are many many ways to have a full LAMP stack on a Windows machine and use it for PHP development like WAMP, for example. This is ok if you are developing just for fun, but in corporate level an on-boarding environment is much preferred. Having a pre-defined server image with all that is necessary to almost replicate your production server on a developer machine helps on preventing errors and, most importantly, quickly have new developers up-to-speed with the corporation development environment.

Consider that you would need:

  • Apache
  • PHP
  • MySQL
  • Memcache
  • APC
  • some extra libs
  • GIT repository

Creating this under windows can be such a hassle and in cases like this bundled solutions does not work.

To create a full LAMP stack on your windows machine and have it 100% stand-alone I have used Vagrant. On the prior version of Vagrant (V1) you had to use Putty in order to ssh to the VM and that was a painful process, with the newer version (V2) you can use built in Vagrant SSH as long you install an SSH support library like the one from GIT. There is a trick on the GIT installation, you must choose the option with the Linux / Unix commands (it has a red warning message about overwriting windows libs).

Prior installing Vagrant you will need to install Virtual Box. It is a Oracle virtual box machine. Very useful if you are on OSX or Linux and need to run tests on Windows IE9 (sig). This part of the process is very well explained on the Vagrant documentation.

Now comes to Vagrant install. It is fairly easy. Install Vagrant, then open command line and run “vagrant init”. It will create a default vagrant file with most of the basic things defined. Here comes a trick. The default vagrant file tries to download the precise VM.  I have tried to contact Vagrant a couple times on Twitter and with no luck. There is an issue with the download of this box, the server resets the connection prior the download to be finished.

There is a way out of this: VagrantBox.es – Select the box that you best consider that matches your environment, add it on vagrant (vagrant box add) and finally update the vagrant file to use the new added box.

After this, everything is as simple as setting up the environment. Unless you have an specific need to add the GIT repository files under another folder you can set it all under the vagrant folder (same folder where the vagrant file is located).

I could use the GIT command line on windows to clone / commit my repositories, but using the GIT windows tool from GitHub is way too fun 😀

I know that most of PHP developers use either Linux or OSX for development. It is much easier to setup and use, but if you are stuck with Windows, you might as well benefit of this.

Just a note, off course the main environment mentioned here was LAMP, but this same process can be used for Ruby, Phyton and may other hipster languages available =D

 

Updates:

I had a networking issue with the current box that I’m using. It seems that it is a common issue with some boxes as mentioned here – https://groups.google.com/forum/?fromgroups=#!topic/vagrant-up/Yeu6UF-GJO8

To fix run this: sudo /etc/init.d/networking restart

If you never installed a LAMP stack before, this article here will give you all the steps to install it correctly: http://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-ubuntu-12.04-lts-lamp

Advertisements

Simple MySQL Heartbeat monitoring

I had an interesting request today: create a script that would return a page header 200 or 500 for a heartbeat monitoring on a MySQL server for a site. The reason behind it was that the server was returning way too many MySQL connection errors during a small period of time for it to considered a simple app error.

This is what I have came for to help with the issue:


<!--?php
$dsn = "mysql:dbname={$dbName};host={$host}";
$user = 'mysql_username';
$pass = 'mysql_user_password';
try {
$dbh = new PDO($dsn, $user, $pass);
$dbh = null;
header("HTTP/1.1 200 OK");
} catch (Exception $e) {
header("HTTP/1.1 500 Internal Server Error");
}

With this simple code we can monitor the page status and if it returns 500 set an alert to tell us that MySQL server is down.

There are, off course, better ways to do this, but if you don’t have too many resources or is using a shared server, this might be a good solution meanwhile.


How to begin on Front End Development

A friend of mine asked me today how could he begin on front-end development without knowing anything at all of programming and bellow is what I have pointed out to him. These links should get anyone started with basic concepts of front-end development and learning should be easier after that.

Some links to get you started on HTML, CSS and JQuery (Javascript)

Med-advanced

Get used to concepts like Responsive CSS (it’s great) and for those you can use test tools like: http://screenqueri.es/ to check if everything is ok.

Get into Twitter and Google+ and  follow me on those (you can get the links at www.mcloide.com) and you will see that there is a bunch of people that I follow that are in regards of CSS, HTML and Javascript. There is always a bunch of new things that you can learn from developers that work with front-end in a daily basis.

You can also check hubs like Coderwall and Geekli.st where you can find info, tutorials and tips on HTML, CSS and Javascript.

As tips remember this:

  •  IE sucks -> it will break your design / css / html / etc so if it works on IE it works on everything else
  • Google is your best bud -> there is always someone with the same problem or a similar problem as the one you are having
  • in backend programming we use the concept of DRY (don’t repeat yourself). In HTML you might not be able to use it, but for both CSS and Javascript you can use it.
  • You can use JS Lints (http://www.jslint.com/) to check if your code is pristine
  • You can use Fiddles to test some stuff on the fly (http://jsfiddle.net/)
  • Use either Chrome or Firefox while developing, the Firebug and Chrome Inspector are excellent tools to check on javascript errors, small inline css changes, etc
  • The best way to practice and start, build a site, publish it and ask for a review on it from other dev’s / people – it will give you ideas of UX and if you need to improve your code.

I’m not a front-end developer, but these are the steps that I usually take when I need to code something for front-end. Either way is a good start for anyone that haven’t coded anything in front-end or is simply considering on starting on web-development altogether.


Learning from the Amazon AWS Outage

I’m a old schooler, I have been programing and dealing with computer systems since mid 1990’s. At that time we did not had all of the cool tools that we have today and everything was dealt with paranoia.

In another words what I’m trying to say is that from experience, there are ways to deal with situations when the sh** hit’s the fan.

Today’s Amazon AWS outage (can’t call a hiccup something that is lasting more than half an hour) either brought down or slowed down sites all over the world. This could have been avoided if business had a simple contingency plan.

Most of today’s mid and large sized web applications use a third party service to host the application, databases, etc. With the increasing demand the Cloud services become more and more popular and the migration of in-house service to third-party service just become natural. If the server died on the third-party, they could replace it with a faster time than if done in-house. With similar reasons the in-house servers became relic and the contingency plan become forgotten. No one would guess that a whole data-warehouse would go down right !?

For whatever reason today Amazon AWS service went down on US-Area-1 (or Virginia) and they stayed (or still are) down for a considerable time. The question that you should be doing right now is: What had to be done to prevent my web application to go offline or slower because one or more servers (doesn’t matter the type – app or db) are offline?

I’m not a DevOPS and I really can’t go deep on the subject, but based on experience (or simply paranoia), here  is an idea. Everything today is distributed, so it should be your server instances under the load balancer. Truth is whoever doesn’t have that today probably got the web application fully offline.

In defense of Amazon AWS, you can choose the areas of service of your servers and, with the exception of Virginia, all the other service areas are working just fine. Even knowing that is pretty bad that a whole area got knocked off, your application should not if you have the server instances correctly setup.

I might be saying the obvious here, but I recall a friend telling me that he was at a conference and all other participants that worked on very large websites were spooked because he mentioned that he had all his server instances with only one single service provider.

Obvious or not every business should prepare a contingency plan. A plan that will give answers and restore it to full working conditions in no or little time in the case of the worst case scenario.


Improve performance: Save the Request and Use Signed Cookies

These are 2 ideas that I have just heard on a presentation. To gain performance with your application, save the requests (dont worry much with pageload) and use a signed cookie to autenticate uses instead of checking the sessions.

The save the requests concept is pretty simple: If you browser already cached something, unless you really need to reload that file, save that request and let it cached. For example, don’t change an image name or add an identifier to a css file unless strictly needed. That will save a request, therefore gaining performance.

The signed cookie is an interesting concept. If you take a look, the read time to the database (or cache mechanism) to check if the use is authenticated is greater than your application checking for a signed cookie. Read the cookie and if is there, authenticate the user.

I really did like these 2 ideas and probably will start using them on my apps. Anyway, sharing the tip.


Who tested this sh***

One of my colleagues was testing something and found out that a cron that was consuming 100% of memory and never ended. He is not a PHP Developer so he called me to take a look.

After less than a minute looking on the code I found the issue but I was perplexed to see how a code like that went to production.

In short this was the main execute code of the cron:


while(!empty($all)) {
$row = array_shift($all);
}

As you can imagine, that array will never be empty, so the loop will never end.

Fixing it was very easy, a simple change from while to foreach took care of the issue, but a question remains for me: who tested this sh***

Obviously it wasn’t tested, otherwise this would have been caught way prior getting to production.

Sorry about my rant but I can’t avoid to get mad when I see a developer that did not even run the code prior commit it.


Scalable JavaScript Application Architecture

Awesome presentation from a former Tech-Lead from Yahoo.


%d bloggers like this: