Category Archives: AWS Cloud

Scheduling task on web server to database

Although it sounds simple, but please trust me that it always troubled me.

OS level Cron is a good choice but it does not have any protection against multiple execution. Let’s imagine you have created an event that executes every 10 seconds, but the logic inside the event (i.e. curl) can take longer than 10 seconds, so it can pile-up. In the worst case, when an event contains a follow up action of ‘insert’ query, it can cause duplication.

MySQL Event Scheduler that available on version 5.1.6 is at the database layer implementation but it has some way to avoid deadlock. https://www.percona.com/blog/2015/02/25/using-mysql-event-scheduler-and-how-to-prevent-contention/

Database layer of scheduler is useful if you just wanto modify the data without other ‘external’ action such sending email or calling another php script. It is also useful for database hosted on AWS RDS cloud.

Gearman is another totally different tool but kind of related. http://gearman.org/

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages. It can be used in a variety of applications, from high-availability web sites to the transport of database replication events.

Imagine you crawling multiple website base on today captured records. Gearman help you distribute task evenly across available client, changing a ‘serial’ process into ‘parallel’. The speed it give you help to avoid the above mentioned deadlock situation. However, it still not protect against multiple execution.

For now, I find this article very helpful: http://bencane.com/2015/09/22/preventing-duplicate-cron-job-executions/

Web Hosting

I started my first web hosting with Xoom in 90s and then Geocities. They are both free hosting services. Thanks to hosting company like Lunarpages and Exabytes, I able to afford my own cpanel hosting at reasonable fee as low as RM300 annually. I even subscribed for a reseller plan so I can host multiples sites under one WHM. Now, I am more keen to use cloud services such as Heroku, AWS, Azure and Google Hosting. My recent favorite cloud provider is Digital Ocean. I had tried both Heroku and AWS and they are all charge like utilities bill base on usage, which can be very expensive for my free project. Digital Ocean offered fixed price and somehow I feel the vm are more stable than AWS Ec2 although Amazon S3 are still my all time favorite when come to storing static files. With emerging trend like dns cloudflare, baas parse.com, smtp mandrill… it seems that all infrastructure can be provided as service base (IaaS) and programmer can more focus on coding than setting up server.

AWS AWSome Day KL Free Credit Redeemed

After finished the online training on EC2, S3, RDS which I already familiar with, I finally received the remaining USD75 credit thru email from amazon. aws75credit Many thanks! Sum up with the USD25 free credit that obtain by attending AWSome Day KL in cyberjaya, I accumulated a total of USD100 credit. Well, my monthly expenses on AWS is certainly more than this amount but I appreciate this marketing approach. awstotalcredit   Thanks again to Amazon and I do hope your pricing can keep reducing from time to time as your scale of economy increase.

Using S3 for web storage with PHP

Amazon S3 is a reliable and affordable cloud storage. When you host a file up there, it is automatically scale-able. Not to confuse with your traditional hosting ftp diskspace, s3 is meant to store static files like images, html, js, css and etc; but not dynamically executed server side code like PHP. In this tutorial, I will teach you how to create a web enabled s3 bucket and how to use PHP code to upload your content onto it. An S3 bucket is a grouping or set of discrete storage container where you can define specific rules and condition. For example, you can create a bucketA which is private while another bucketB which is publicly accessible from the web. You can also create another bucketC which only serve to log access data generated from the bucketB. Be notice that each bucket name have to be globally unique and follow the naming convention here. Your bucket name will also be part of your url if you choose to open the bucket to public. You can have unlimited folders and files inside a bucket. Create a web access bucket s31 Login to your AWS web console, goto S3 section. Click “Create Bucket” button found on the top right of page. s32 On the right is your bucket properties. We will need to make changes to Permissions and Static Web Hosting section.   s34 For static web hosting section, note down your end point url. Then click the Enable Website hosting radio button. Do not forget to insert your index document name too. In this case, i just use index.htm. If this file is missing, it will show a 404 File not found HTTP error page. Unlike a convention HTTP server, it wont display a list of other files found in this directory.   s33 For Permission section, Click on the Edit Bucket Policy button. Then, insert the code as shown. Remember to change your resource name to match your bucket name. This move is to give right to the public to have read access on your bucket and every files/folders in it. Ok, now you have successfully created your bucket and may test it with the endpoint url. Download Amazon SDK for PHP Next, we will download Amazon SDK for PHP. As amazon update their SDK frequently, the following information might be out-dated. However, the concept would still be the same. Visit http://aws.amazon.com/sdkforphp/ for the download file link. Click ‘AWS SDK for PHP‘. Notice the file downloaded is aws.phar. PHAR is a very nice feature from PHP 5.2 and newer for easy distribution and installation. Writing PHP code to upload file to s3  

Malaysia AWSome Day @ Cyberjaya

I have been using AWS for years, mainly on EC2 and S3. I am so glad when first heard that AWS is coming to KL Malaysia for the very first time. They also picked a great vanue, Cyberjaya, which is where my office located. So, back to the uni time huhh… I was expecting some onspot lab hands on but it’s more like a general introduction. The lab part will be done online later at my own comfort. 20131017_121115 Got some sticker as door gift: 20131018_234708 I will share more about the online lab when I got my login info.