Tag Archives: technology

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


ibuypower

I have just purchased a notebook with iBuypower.com. Truth is that I have never heard about them before or never knew anyone that had purchased any computer with them, still they were the few websites available that offered customized systems. This is my review of the notebook and their services thus far.

Searched through a few forums and finally I have found a good reference from them, they had systems to be sold in Newegg.com. Everyone knows Newegg.com.

This are the settings that I have asked for the notebook:

1 x Case (Battalion 101 W350ETQ 15.6″ Full HD 1920×1080 Widescreen LED TFT Laptop w/HDMI Port, USB 3.0 port, fingerprint Reader, Li-Ion Battery, Universal AC Power Adapter – Original Metallic black))
1 x Processor (Intel® Core™ i7-3630QM Mobile Processor (4x 2.4GHz/6MB L3 Cache)))
1 x Memory (16GB [8GB x 2] 1333MHz DDR3 SDRAM [Laptop Memory] – Corsair or Major Brand **FREE Upgrade to 16GB [8GB x2] DDR3-1600 G.Skill**))
1 x Video Card (NVIDIA GeForce GTX 660M 2GB GDDR5 Video w/ NVIDIA Optimus [W350ETQ]))
1 x Primary Hard Drive (256 GB ADATA SP900 SSD – Single Drive))
1 x Data Hard Drive (500 GB 5400rpm Serial-ATA Super Slim Laptop Hard Drive))
1 x Optical Drive (8x Dual Format DVD±R/±RW + 16x CD-R/RW Combo Drive [W350ETQ]))
1 x Sound Card (3D Premium Surround Sound Onboard))
1 x Network Card (Built-in 10/100/1000 Mbps LAN [Laptop]))
1 x Operating System (Microsoft Windows 7 Professional + Office Starter 2010 (Includes basic versions of Word and Excel) – 64-bit))
1 x Warranty (Standard Warranty Service – Standard One(1) Year Limited Warranty + Lifetime Technical Support))
1 x Rush Service (Rush Service Fee (not shipping fee) – Deferred Delivery (Ship Out in 15 ~ 20 Business Days) – 5% OFF on systems over $999 (Coupon Code: defer)))
1 x USB Ports (Built-in 1x USB 2.0 + 2x USB 3.0 + 1x USB 3.0 / eSATA Combo Ports [Laptop]))
1 x Video Camera (Built-in 2.0 Mega Pixels Digital Web Video Camera))
1 x Internal Wireless Network Adapter (Intel Advanced-N 6235 802.11 a/g/n 300Mbps Dual-Band Wi-Fi + Bluetooth Combo))
1 x Flash Media Reader / Writer (Built-in 9-in-1 Media Card Reader/Writer [Laptop]))
1 x Carrying Case (Free Deluxe Carrying Case))

I was waiting this notebook to be awesomely built and it is.

These are the pros:

  • extremely well packaged. It was so protected that the ratio for the box x contents was of 4 x 1 (the box was 4 times bigger than its contents and filled with foam and popcorn-foam)
  • beautiful body
  • onkyo speakers
  • extremely awesome resolution screen
  • came with a windows 7 recover dvd (and some other drivers installation dvds). I personally loved this because the last notebook that I have bought didn’t came with it and gave me a huge headache to recover everything when the hard drive failed.
  • Their customer service rocks. Ok, they had a miss communication with me in one of the emails, but on the phone everything was rectified.

So far these are the cons:

  • deferred shipping (I really did a very dumb decision when I have chosen this discount – dont do it)
  • battery runs out pretty quickly when using it on max power

 

I will be putting this note to the test today. Started downloading Guild Wars 2 and I will install a Virtual Machine with tunneling to use as my webserver.

In general, right now, I would buy from them again. I’m very satisfied with the notebook and they do deserve two thumbs up.


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.


A scenario that should have failed

Today something happened to me that by chance I was luck enough to find out. By all means it was a scenario that should have failed and it did not.

I had an account and it was closed (so no more transactions were supposed to go to it) on the 19th. On the 29th I had  a payment (Real Time Bank Transfer)  with a vendor. I forgot to update with the vendor the account details and a transaction was posted. I don’t think, in my widest nightmares, I would had a closed account accepting a transaction. It not only accepted a transaction over an closed account but also accepted a transaction over an account that had 0.00 as balance (this last is more acceptable since banks have overdraft fees).

Few days later, checking the balances on the new account (that was supposed to have the transaction), the transaction wasn’t there, so I have assumed that it had failed. Checked with the vendor and surprisingly enough the vendor was happy, wich means that the transaction went through. Checked with my dad, that received the transfer, and he also did had the amount. By exclusion it means that the transaction was posted on a closed account (simple troubleshooting came in hand).

Hold right there: How come a closed account have accepted a transaction?

That was my 1st question when I did go to the bank branch to check if the transaction went through on the closed account. After a 1 and half hour of trying to figure out the issue with the representative we got things sorted out. The bank admitted that they did a mistake. A mistake that in my opinion  is pretty bad one.

Just so you can have an idea: Foreach negative transaction there is an overdraft fee, charged per day, of $35.00. In 30 days that would had costed me: $1050.00.

Kind sucky to know that a system mistake would had cost me over a thousand USD in a month and a ridiculous amount in a year.

Things were sorted out. The bank now knows about the system error and for myself, I got a couple of documents proving that the account was closed and clean, so if any day I get someone to try to collect me anything, well, I have proof that things are ok.

I’m not sure what made me perplexed, knowing that this kind of error happened or knowing that this kind of sh** always happens to me. Who tested this sh** ?

 


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.


The worst type of website failure

This is a small story, that happened with me this weekend and I will post it bellow so you can also see the worst, in my opinion, type of failure of a website.

Yesterday I was set to change my current cable provider to Comcast. The reason was simple, prices. Compared to my current cable provider, Advanced Cable, they have a lower price for the same features.

Anyway, I have checked for my address, started a chat with a representative and selected a product to go on. After a long talk with the representative and correctly setting all the points that I needed to go on with the order my checkout was blocked with a message: Please call the Xfinity customer support to finish this checkout. Your address could not be found on the database.

That immediately issued a red flag for me. Calling about my address not being on the database? Ok. I’m not a client so that might be it, but still that can’t be good.

Called customer support and I heard the bad news: We cant provide service in City. You will have to go with Advanced Cable (witch is my current provider).

Until I have got to this point I have spent at least 2 hours planning, talking with reps, setting everything online and everything was pointing out to be good. The address checked, I had a good product option, prices were good. I was even considering to accept a contract, but it failed.

Why does the  Comcast website says that you can provide service to my address and the customer support on the phone says that it cant?

Regardless of the reason that is a horrible mistake. A potential client went through a very long process to checkout, could not checkout and even if he wanted to, he would not be able to checkout. This is a horrible logic error because that information should have been validated on the beginning of the process.

The “bug” here is simple. If this was a shopping cart, it would be the same as letting a shopper to purchase a specialty product in USA that can only be sold in Europe. If the validation of the shopping cart was done in the begging of the process there is a good chance that, if possible, the client would still keep shopping for other products. In the case of Comcast and me, I couldn’t go further even if I wanted to, but I would consider them if I ever changed of address.


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.


Capistrano Get-Servers

This is awesome resource from a good friend of mine.

Capistrano::Getservers

capistrano-getservers makes it easier for you to deploy to your EC2 instances. By supplying a Hash to theget_servers method, capistrano-getservers connects to EC2 and retrieves all instances with matching tags.

Check it out:

https://rubygems.org/gems/capistrano-getservers


%d bloggers like this: