Knowledge7

The Linux and Mobile Solution Provider

  • About
  • Training
  • Services
  • Clients
  • In the news
  • Blog
  • Contact Us
You are here: Home / Archives for Avinash Meetoo

File and Directory access

This topic is part of our Web Development with PHP and MySQL training

In a lot of applications, users need to be able to upload files. For example, most social networks allow users to upload pictures.

We will modify the web application to allow users to upload pictures when they are viewing details about a specific phone. After some time, other users will be able to browse a gallery of user-uploaded pictures for each of the phones.

To do that, we will use the file upload capabilities of PHP.

It is important to make sure that the uploaded file is of the proper kind and size.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Using MySQL

This topic is part of our Web Development with PHP and MySQL training

MySQL supports transactions. This allows software developers to create application which preserve data integrity even in the event of (software or hardware) failures.

The work to do is to use transactions as provided in MySQL to protect all collections of queries which should be treated as being atomic in nature.

Another important feature of MySQL is stored procedures. These procedures exist in the database and, when called from a PHP application, can greatly increase performance. Furthermore, stored procedures allow multiple applications, written in PHP or not, to behave in a consistent manner.

The work to do is simplify the checkout of cart items using stored procedures.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Using sessions and cookies

This topic is part of our Web Development with PHP and MySQL training

HTTP is stateless. Consequently:

When a web server is required to customize the content of a web page for a user, the web application may have to track the user’s progress from page to page. A common solution is the use of HTTP cookies. Another method include server side sessions.

PHP supports both sessions and cookies and, as such, allow us to transform the web application into one which supports multiple users concurrently. In other words, the work to do is to transform the web application into one where multiple users can log in and order phones at the same time. We will use PHP sessions to implement those new functionalities.

Additionally, we would like to implement a “Show popular phone of the hour”. We will use PHP cookies (with appropriate expiration dates) to implement this functionality in such a way that queries to the database are minimal.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

How to maximise performance when using MySQL

This topic is part of our Web Development with PHP and MySQL training


Since version 5.0 of MySQL was released in October 2005, a lot of new features have been added to it to make it standards-compliant, secure and efficient. In 2011, MySQL 5.5 is still an open source software and is freely downloadable for various platforms. In this blog entry, I will focus on performance in MySQL.

MySQL provides two important utility statements, EXPLAIN and PROCEDURE ANALYSE, which can be used to understand where performance bottlenecks are. EXPLAIN is used to obtain information about how MySQL executes a SELECT statement. PROCEDURE ANALYSE suggests optimal data types for each column that may help reduce table sizes. Also, as MySQL exposes its inner workings to the database administrator, one can go very far in optimising performance.

One simple way to increase performance is to create indexes as they generally allow queries to run more quickly. Care must be taken to only create indexes when really needed as indexes consume space. In some special case, indexes can, in fact, decrease performance.

In the real world, web applications are used by concurrent users and it is important to use transactions and proper locking mechanisms in order to preserve the integrity of data. Of course, it is also important to understand that transactions and locking can have a negative impact on performance.

Whenever the same sequence of SQL statements is done over and over again, there is an opportunity to use a stored procedure which is just a set of SQL statements stored in the database server itself. Consequently, clients don’t need to issue the individual statements but can refer to the stored procedure instead. As written in the MySQL documentation, stored procedures can provide improved performance because less information needs to be sent between the server and the client. The tradeoff is that this does increase the load on the database server because more of the work is done on the server side and less is done on the client (application) side.

One recently added feature of MySQL is partitioning. This allows different portions of a table to be stored as separate files in different locations on disk. The rule used for doing the partitioning is specified by the user. Some queries can run much more quickly when a table is partitioned in virtue of the fact that data satisfying a given WHERE clause can be in one (or a few of the) partition(s), which obviously excludes any remaining partitions from the search.

Finally, given the prevalence of storage systems with very high I/O rates compared to our classical hard disks (e.g. solid state devices), MySQL has an adjustable I/O rate which can be tweaked to maximise performance.

We will cover some of these interesting aspects of MySQL in our coming Web Development with PHP and MySQL training starting on 25 July and 8 August.

One thing is sure: MySQL is far from being a toy.

This topic is part of our Web Development with PHP and MySQL training

Our forthcoming training courses

  • No training courses are scheduled.

Picks of the Week #7

You want to receive our Picks of the Week every Monday morning?

Thank you for reading the seventh edition of Knowledge7’s Picks of the Week which exceptionally focuses entirely on the MySQL database server and associated software.

We are happy to offer you a 10% discount off the normal price of our coming PHP/MySQL training courses.

Every week, Avinash Meetoo will make you discover interesting articles and websites to help you broaden your understanding of the world of open source software and information technology in general.


Nuts & Bolts: Database Servers
37signals is the company of David Heinemeier Hansson, creator of Ruby on Rails. 37signals make the incredibly popular Basecamp, Highrise, Backpack and Campfire web applications which, because of their large number of users, do have very stringent MySQL performance requirements. As they write on their blog, “All of our applications, with the exception of Basecamp, follow a pretty similar model: We take a pair of Dell R710 servers, load them up with memory and disks, and setup a master/slave pair of MySQL servers. We use the excellent Percona Server for all of our MySQL instances and couldn’t be happier with it.”. For Basecamp, the decision was to purchase a pair of MySQL appliances with solid state drives and optimised for I/O performance.”

MariaDB
First, in 1994, there was MySQL AB where Michael “Monty” Widenius created MySQL, arguably the world’s most popular database. Then, in 2008, Sun Microsystems acquired MySQL AB and Monty was happy. When Oracle acquired Sun Microsystems in 2010, Monty became less happy and he decided to create MariaDB, “a community developed, stable, and always free fork of MySQL that is compatible with the main version Oracle MySQL.” In other words, if, one day, Oracle decides to charge for MySQL (or kill it), it won’t be a big issue as MariaDB is a drop-in replacement. I can easily imagine some people preemptively moving from MySQL to MariaDB just as a precaution. Or not. Depends on you.

Drizzle
[I mentioned Drizzle in a previous Picks of the Week]. Another fork of MySQL is Drizzle: “a community-driven open source project that is forked from the popular MySQL database. The Drizzle team has removed non-essential code, re-factored the remaining code and modernized the code base moving to C++.” Drizzle has a number of innovative features that makes it very powerful: it is “optimized for Cloud infrastructure and Web applications”, is “designed for massive concurrency on modern multi-cpu architecture” and it “optimizes memory [usage] for increased performance and parallelism”. In other words, when performance is key, then you need to spend some time evaluating Drizzle even though it is a relatively young product.

Percona Server
Instead of using MySQL, 37signals uses Percona Server, yet another fork of MySQL. Percona Server, “an enhanced drop-in replacement for MySQL”, allows “queries to run faster and more consistently”. The people behind Percona Server put a lot of emphasis on performance, completely eliminating the lockups that MySQL sometimes suffers from. They also have put a lot of emphasis on scalability: Percona Server has been designed to use up to 48 cores and to issue hundreds of thousands of I/O operations per second on high-end solid-state hardware (SSD). Percona Server also allows the database administrator to measure all performance characteristics through a very complete instrumentation dashboard. Percona Server is open source software and, therefore, free to use.

Percona XtraBackup
To conclude this MySQL special, we need to talk about backups. All database administrators know that backups are essential and need to be done on a regular basis… preferably without having to stop the database server and, therefore, interrupting business activities. “Percona XtraBackup makes hot backups for all versions of Percona Server, MySQL, MariaDB, and Drizzle.” Being hot, the backups are made while the database is in use. XtraBackup naturally supports incremental backups which means that “backups complete quickly and reliably” and there are substantial “savings on disk space and network bandwidth”. Like Percona Server, Percona XtraBackup is also an open source software, free to use!

We thank you if you have already responded to our Survey on Training Needs in Mauritius. If you have not yet answered, please do so. It will only take two minutes.

Our forthcoming training courses

  • No training courses are scheduled.

Linux Kernel

This topic is part of our Linux Network Services and Security training

The Linux kernel is open source software and, consequently, its source code (millions of lines of C) is available.

Sometimes, it is important (and interesting) to compile either a specific kernel module (typically because of a bug correction) or to compile the whole kernel. Of course, it is technically possible to download the latest Linux kernel, compile it and install it on an enterprise Linux distribution like RHEL or CentOS but this is not recommended.

Instead, Red Hat and CentOS recommend to obtain the source code of the kernel which is already in use in those distributions, configure it, compile it and install the compiled kernel without removing the previous one(s).

When using CentOS (for example), the first step is to obtain the source code of the kernel and unpack it correctly.

Then, depending on user requirements, the system administrator can:

  • either build one kernel module (e.g. to correct a bug) and use that corrected module in the current kernel
  • or rebuild the whole kernel and install it without removing existing kernels.
This topic is part of our Linux Network Services and Security training

Our forthcoming training courses

  • No training courses are scheduled.

NFS and Samba

This topic is part of our Linux Network Services and Security training

Network File System

Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. NFS is configured by editing /etc/exports. Note that the defaults settings for NFS shares are ro (read-only), sync, wdelay and root_squash. It is possible to use all_squash and specify anonuid and anongid. Hostnames should follow a specific format.

The mount command (when used with the appropriate options) can be used to connect to an NFS share. Naturally, one can also edit /etc/fstab so that NFS mounts are done automatically at boot time.

Samba

Samba is an important software as it allows Linux computers to easily communicate with computers running Windows.

Samba can:

  • Serve directory trees and printers to Linux, UNIX, and Windows clients
  • Assist in network browsing (with or without NetBIOS)
  • Authenticate Windows domain logins
  • Provide Windows Internet Name Service (WINS) name server resolution
  • Act as a Windows NT-style Primary Domain Controller (PDC)
  • Act as a Backup Domain Controller (BDC) for a Samba-based PDC
  • Act as an Active Directory domain member server
  • Join a Windows NT/2000/2003/2008 PDC

What Samba cannot do:

  • Act as a BDC for a Windows PDC (and vice versa)
  • Act as an Active Directory domain controller

Samba can be configured by editing /etc/samba/smb.conf but most people prefer using a graphical tool such as SWAT (it is important to add FLAGS = IPv4 in its xinetd configuration). When configuring Samba, it is possible to create a share:

[shared]
comment = This is a Linux share
path = /home/shared/
valid users = john, jane
public = no
writable = yes
printable = no
create mask = 0644

Valid users (e.g. john and jane in the above example) need to be assigned SMB passwords which can be distinct from their Linux password. The smbpasswd command need to be used.

Shares can then be accessed using Nautilus and even mounted in Linux using the cifs filesystem type. Samba comes with a number of useful command line tools which system administrators should be aware of.

This topic is part of our Linux Network Services and Security training

Our forthcoming training courses

  • No training courses are scheduled.

Infrastructure services

This topic is part of our Linux Network Services and Security training

Dynamic Host Control Protocol (DHCP)

Linux can be used as a DHCP server.

Quoting the official Red Hat Deployment guide, “DHCP is useful for automatic configuration of client network interfaces. When configuring the client system, the administrator chooses DHCP instead of specifying an IP address, netmask, gateway, or DNS servers. The client retrieves this information from the DHCP server. DHCP is also useful if an administrator wants to change the IP addresses of a large number of systems. Instead of reconfiguring all the systems, he can just edit one DHCP configuration file on the server for the new set of IP addresses. If the DNS servers for an organization changes, the changes are made on the DHCP server, not on the DHCP clients. When the administrator restarts the network or reboots the clients, the changes will go into effect.”

The preferred way to configure a DHCP server is to start from a sample dhcpd.conf.

Domain Name Service (DNS)

Linux provides Bind, a full-fledged DNS server. Bind can operate as a caching nameserver as well as a DNS server which is fully authoritative for a zone (or many zones). The preferred way to configure Bind is to start from sample named.conf and zones.

This topic is part of our Linux Network Services and Security training

Our forthcoming training courses

  • No training courses are scheduled.

Picks of the Week #6

You want to receive our Picks of the Week every Monday morning?

Thank you for reading the sixth edition of the Knowledge7’s Picks of the Week.

Every week, Avinash Meetoo will make you discover interesting articles and websites to help you broaden your understanding of the world of open source software and information technology in general.


The Metasploit Framework
There is currently an ongoing battle between pirates and system administrators. And, of course, given the prevalence of Linux on the Internet, this is true for Linux system administrators too. “The Metasploit Framework is both a penetration testing system and a development platform for creating security tools and exploits. The framework is used by network security professionals to perform penetration tests, system administrators to verify patch installations, product vendors to perform regression testing, and security researchers world-wide. The framework is written in the Ruby programming language!”

The Mirah Programming Language
“Mirah (nee Duby) is a new experimental language born out of the JRuby project. In order to make implementing Ruby on the JVM easier and more approachable for Java and Ruby developers alike. Charles Oliver Nutter wanted to create a language that essentially looked like Ruby, but was statically typed and compiled to fast JVM bytecode. Mirah is the result.” What is sure is that the Java programming language is starting to show its age: its syntax is based on an ancient language called C++ (remember that?) and its programming model is too complex (is an integer an object?). Does Mirah has a chance to succeed? Only time will tell. But it’s going to be tough with Scala, Clojure as well as JRuby (mentioned above) innovating on all fronts…

The Facebook Blog: The Spirit of Openness
“Here’s a secret: Mark Zuckerberg didn’t write all of Facebook in his dorm room at Harvard. (Sorry, Mark, your secret is out.) He had a lot of help. No, I’m not talking about all the wonderful folks who work on the site every day. I’m talking about the unsung hero of many a young Web site: open-source and free software. Without it, there’d be no Facebook.” “Almost all our servers are running open-source software. Our Web servers use Linux and Apache and PHP. Our database servers run MySQL. […] The list goes on—like many Web sites, we use it from top to bottom.” “But we also make it a point to give back.” To all those who want to build the next Facebook in Mauritius: follow a decent PHP/MySQL training. Why not something like ours? 🙂

Drizzle: A Database for the Cloud
“Drizzle is a community-driven open source project that is forked from the popular MySQL database.” Here are its main features: “optimized for Cloud infrastructure and Web applications”, “designed for massive concurrency on modern multi-cpu architecture”, “optimized memory [utilisation] for increased performance and parallelism” and (of course) “Open source, open community, open design”. Why fork MySQL you may ask? The Drizzle developers say that they wanted to “remove non-essential code, refactore the rest and move towards C++”. What they get is a database which is reliable, which supports transactions and which is ACID compliant (atomicity, consistency, isolation, durability). Phew. I initially thought that they forked MySQL because of Oracle…

How to Pick a Co-Founder
When I founded Knowledge7 at the end of 2008, I didn’t pick a co-founder. Sure, I was not alone, we were seven shareholders (hence the name!). But, in hindsight, I should have asked one of them to join me at Knowledge7 as a co-founder. I would have chosen the one who has “a complementary temperament” with mine, with skills sufficiently different from mine, someone who “shares my expectations” of life, someone who has the “same overall vision” for the company, someone with whom I’ve worked with in the past and someone I like. In other words, I should have asked my wife, Christina, to join me 🙂

Our forthcoming training courses

  • No training courses are scheduled.

Using UI Component tags

This topic is part of our Web Application Development in Java training

Struts contains a number of powerful UI (User Interface) components. In essence, each UI component:

  • Generate (complex) HTML
  • Links HTML form fields to Java properties
  • Does automatic type conversion and validation

Out of the tens of UI components, four are very powerful while being relatively easy to use. They are:

  • select
  • radio
  • doubleselect
  • updownselect

Work to do

Write a Struts web application which showcases the four above UI components. Look at the image above for some inspiration…

Bonus

Want autocompletion like in Google Search? Look no further than the autocompleter tag. Try it!

This topic is part of our Web Application Development in Java training

Our forthcoming training courses

  • No training courses are scheduled.
« Previous Page
Next Page »

Looking for something?

Want to know more?

Get our newsletter

Discover the latest news, tips and tricks on Linux, the Web and Mobile technologies every week for FREE

This work is licensed by Knowledge7 under an Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.