Free vs Premium WordPress Themes

Looks like since the beginning of 2013 less new free WordPress themes have been released compared to last year and a big increase on web templates market places on paid premium themes.

Another problem for some people would be that most of the current free WordPress themes aren’t maintained anymore and this sure is a security issue.

Next step in this evolution (plugins included) is an increase on the price as solutions for stoping piracy will be taken care.

How to speed up your WordPress site

Previous I’ve made a brief introduction about what should be on a server that hosts WordPress and other sites.

After many years of working with WordPress and other CMS software I understood that 3rd party tools like CloudFlare or other accelerators are the last options to think about in case of huge amount of traffic (really huge, I mean over 25k unique visitors per day).

So lets start with the basics.

In case you have an old WordPress install, a good starting point would be to export/import your content to a fresh install. This will make sure you have clean files, all unneeded files from upgrades are gone and would make sure your security it’s at a better level. It’s not hard to do this, as WordPress is intended for fast installs, easy import/export etc.

To have the site URL transparent used, you can use this settings in wp-config.php.

Another important thing to speed up WordPress is to limit how many plugins you use. I know you want all those shinny and fancy things that knock your preferences, but think if this really are liked by your visitors. 99% of them don’t like them, so stop using them and delete them. As the user can focus on your content and aren’t annoyed by those stupid share and subscribe features, more they will be enjoying to come again. Not those stupid things make user come back, the good quality code is the reason.

So WordPress with only a bit of help from some plugins works decent fast.

Next, crucial, is the theme you use. I know that 80% of you, readers of this post, aren’t web developers or experienced web designers in WordPress or other cool web apps. So it’s important when you choose a theme to be aware of how “heavy” it is. If you are going to download a free theme or buy a premium one, check all things you can read about it and google for other opinions about it. You may be surprised of how many free and even premium themes are very bad quality, they are just looking nice for your eyes. Remember, security and performance are a huge thing for your site, so try to step away from subjective opinions. If you find a really cool theme, but find out that it has really bad code in it, you may pay a good WordPress developer to make a custom version for you, there are lots of good themers, but may cost a bit.

I’m recommending themes from ThemeForest as they have a team of WordPress experts that check each theme. From there you may go to the other market places like for GraphicRiver or PhotoDune for great assets you can use on your site, cheap and really good quality.

With themes, even with good quality ones you may have troubles on one of the next steps.

Next step of optimization can be achieved two ways. Decent speed improvement by using W3 Total Cache with some good configured settings (depends on what the host limits you, so stay away from stupid shared hosting with bad limits – most “Unlimited” ones). Alternative, really huge improvements are by optimizing for your WordPress installation can be done on the servers config (if you have access), exactly in your vhost configuration. First, .htaccess option must be disabled and all rules need to go in here. I use common config files for WordPress and only call them with Include statement in all vhosts I need. This is a nice boost, because if you have .htaccess settings those are read for every client connection (for each file called – that’s a pain). Imagine this on “unlimited” shared hosting where they are hosting even up to 10k sites on a little server.

So, you got read of .htaccess, good, you won’t see improvements as you refresh pages, but when you have some traffic, it’s making difference. Good, now, HTTPD and Nginx can use a great module made by Google, called PageSpeed. This one needs some customization, as even some of the WordPress JS and CSS files from wp-admin are bad written and cause problems. So to skip headaches, I’m making PageSpeed to skip anything from those folders globally. Some great features that PageSpeed does (better then CloudFlare or other 3rd party tools) is that is combines and minifies JS and CSS files better then any other tool out there – it’s f**king Google we are talking about here so don’t pretend you are smarter then them. Using this feature will make you see if you are using a theme with bad css/js. And a nice thing, any known JS/CSS file from their CDN, the path is changed to use the CDN, nice thing, cuts a bit from your server’s load. This things can be achieved even with W3 Total Cache and externalize them to S3 or other CDN 3rd party tool, but I prefer to have everything on my side and let S3 to handle the big stuff, like videos, audio files and big images.

After all this optimizations, if more is needed, you may go with CloudFlare, CloudFront or other accelerators. Personally, I’m using my own alternative to this services with Varnish + HTTPD with PageSpeed and scaling to more servers if needed. Other mention, as I had been forced by the custom taste of some clients to use CloudFlare, I discovered that the free version is doing more damage then improvements in some cases.

Many would not know how to handle this stuff, but there are already specialized services that do this stuff or alternative solutions that they found to work. Cool services are from WPENGINE, PAGE.LY, SINTHESIS, ZIPPYKID. But you still need to get a bit dirty on your hands for many stuff.

If you really aren’t that good Web Developer with big SysAdmin experience to administrate your own VPS or dedicated server, best is to find a guy like this and negotiate with him for custom hosting. This would be the best solution, but not for those very cheap on money. Great things, trustful people costs, so if you are generating money from your “online business” or monetize your blog, be ready to split some of the profit to people that would boost your site.

Coming next is High WordPress Security Tips. Stay tuned and subscribe!

Speed up your server

The last month I got very interested in optimizing the server for production hosting of my projects and clients websites and took it to a better level.

Most of the websites hosted by me are based on WordPress, so I’ll explain how I’ve optimized and lowered resources usage about 70% and improved speed about 4-5x times on page display.

The big difference is that I’m not using shared hosting accounts. I’m managing my own server. I’m a fan of virtualization, I’m using it on my development machine for tests and I sure trust this technology a lot.

First, I have hosting panels, like cPanel, Plesk or any other. Since my first interaction with Linux back in 1998, I became a terminal fanatic and I’m proud to call myself addicted to the classic terminal applications (I love VIM). Hosting panels limit what you need to have on your server and increase CPU and RAM usage a lot – this means you pay more for things that don’t offer you benefits. When you edit config files, then you know exactly how things work and fix errors easier.

Last month I started reading a lot about Nginx. The “cool kids” web server for speed. Well, I don’t agree with it. When configuring Nginx to serve PHP applications and leave the application to handle many things that needs to do, Nginx doesn’t offer great speed improvements. Nginx is better to be used for static serving.

Many admins consider Apache too big or too slow in many situations. Well, from my opinion is that they have no idea to configure and handle HTTPD with it’s full resources. And since HTTPD 2.4, things have changed a lot. Latest version of HTTPD (Apache is the foundation that owns HTTPD, and the software that most people call Apache is really named HTTPD) is able to handle much faster static content and uses a much better way to handle dynamic applications written in PHP, Python or Ruby using a proxy implementation. Current the official version handles PHP files by making tcp connection to PHP-FPM and with a custom patch can handle socket connections to PHP-FPM.

I’m using HTTPD with only the mandatory modules. To handle things, HTTPD has different MPM’s that can be used. Event MPM comes to help when performance is needed. This way I can even use PageSpeed from Google to improve more, but this needs some attention as many idiots write WordPress themes that CSS and JS files aren’t very good with advanced technics of minifying.

PHP-FPM is a new way to use PHP, separating it from the Web server. One major benefit is for accelerating applications, like WordPress, better then was possible from the old FastCGI implementation and another is that you can scale to more servers much easier. With PHP-FPM you can separate users in the system, isolate them, even can implement for security reasons something like a prison without loosing any speed optimization. I’m a huge fan of PHP-FPM.

How do I implement this?

I’m creating a separate pool for each client, doing chroot in his directory (so a client is isolated in “/home/user” and can’t leave his folder in any way) – this increases security. His pool runs only on his user and even if he could escape his folder he doesn’t have rights to list or touch any other user folder (as of directories and files permissions). For speed, each pool has dedicated cpu and ram resources. On top of this, I’m using APC for anything that PHP can cache and PHP-FPM makes sure that the cache is kept (with old FastCGI implementation you don’t have the full benefits of APC, Xcache or other opcache).

Communication in web server is done by TCP or socket connections. Sockets are way more faster then TCP connections.

APC or other opcache is much faster then Memcached, that many of you have heard. Memcached should be used to have common cache when using more then one PHP dedicated server. When serving everything from a single server, APC is first to choose, because for PHP is the fastest way for cache. Second, for MySQL queries, you don’t need on a single server implementation Memcached to cache queries. MySQL has a much advanced cache system and it’s able to serve same queries a lot faster then Memcached. And PHP can connect to MySQL using a socket connection, so this makes it faster then the TCP connection to Memcached.

It’s very important to use sockets instead of TCP whenever you can. So, on my setup HTTPD 2.4 makes socket connection to PHP-FPM that caches any code previous requested and already compiled and caches previous MySQL queries (this needs the application to be written in such way; for WordPress W3 Total Cache can help and I recommend it) and PHP makes socket connections to MySQL that has his dedicated piece of RAM for cache.

On top of this, when more is required for websites with huge amount of visitors, Varnish comes to help. I use it with some sites, but for websites with real time data I don’t recommend it, it’s maintenance increases costs more in this situation.

Another mention is that I’m separating media files (videos, audio and big images) and serving them using CloudFront (with S3 from Amazon AWS) – this explains the low network utilization of my servers.

So this kind of implementation have lowered the resources requirements from about 4GB of ram to about 1GB and CPU load dropped to an average of 0.32 and the server became more responsive then the old HTTPD 2.2 with FastCGI implementation for PHP.

Next is how to speed up your WordPress site.

Here are the results for a starting website that doesn’t have so much traffic for the moment presented by New Relic. I’ll come back with another screenshot next month, as next week the website will be advertised.

PHANT New Relic

iMadalin

15 June 2013

Because of my professional interests I decided to switch to English for all my future posts.

Ascunde titlu si afiseaza logo

Cel mai intalnit pe site-urile web pentru mascarea titlului si afisarea unui logo in locul lui e intalnita o secventa asemanatoare de cod css:

h1.logo a {
  display: block;
  width: 300px;
  height: 100px; /* valori de dimensiuni in functie de logo */
  background: url(logo.png) no-repeat 0 0;
  
  /* si regula ce mascheaza textul */
  text-indent: -9999%;
  overflow: hidden; /* un truc sa mascheze linii ce apar in unele browsere la click pe link */
}

Totusi, aceasta varianta forteaza crearea unui canvas imens si pe dispozitive mobile aceasta duce in multe cazuri la scaderea performantei. Pana nu analizati foarte explicit problema, poate fi greu de inteles, dar e observabila cand se fac teste cu dispozitive mobile slabe ca hardware (totusi, dorim accesarea resurselor de toti utilizatorii targetati si nu toti or sa isi cumpere Galaxy S4 ca vrea muschiul tau de web designer).

O solutie mult mai eleganta si indeparteaza problema canvasurilor in memorie de dimensiuni mari este:

h1.logo a {
  display: block;
  width: 300px;
  height: 100px; /* valori de dimensiuni in functie de logo */
  background: url(logo.png) no-repeat 0 0;

  font: 0/0 a; /* truc sa facem textul ascuns */
  /* ne asiguram ca resetam eventuale mosteniri nedorite */
  border: 0;
  text-shadow: 0;
  color: transparent;
  background-color: transparent;
}

Idee preluata din h5bp

Murach MySQL rezolvare exercitii capitolul 5

# 1
SELECT vendor_id, SUM(invoice_total)
	FROM invoices
	GROUP BY vendor_id;

# 2
# 2 v1
SELECT v.vendor_name, SUM(i.payment_total) AS pt
	FROM invoices AS i JOIN vendors AS v
	WHERE i.vendor_id = v.vendor_id
	GROUP BY i.vendor_id
	ORDER BY pt DESC;
# 2 v2 (official)
SELECT vendor_name, SUM(payment_total) AS payment_total_sum
	FROM vendors v JOIN invoices i
	WHERE v.vendor_id = i.vendor_id
	GROUP BY vendor_name
	ORDER BY payment_total_sum DESC;

# 3
SELECT vendor_name, COUNT(invoice_id) AS invoices_count, SUM(invoice_total)
	FROM vendors v JOIN invoices i
		ON v.vendor_id = i.vendor_id
	GROUP BY vendor_name
	ORDER BY invoices_count DESC;

# 4
SELECT account_description, COUNT(*) AS count_items, SUM(line_item_amount) AS sum_li_amount
	FROM general_ledger_accounts g JOIN invoice_line_items i
		ON g.account_number = i.account_number 
	GROUP BY account_description
	HAVING count_items > 1
	ORDER BY sum_li_amount;

# 5
SELECT account_description, COUNT(*) AS count_items, SUM(line_item_amount) AS sum_li_amount
	FROM general_ledger_accounts g
		JOIN invoice_line_items i
			ON g.account_number = i.account_number
		JOIN invoices
			ON i.invoice_id = invoices.invoice_id
	WHERE invoices.invoice_date > '2011-04-01' AND invoices.invoice_date < '2011-06-30'
	GROUP BY account_description
		HAVING count_items > 1
	ORDER BY sum_li_amount;

# 6
SELECT account_number, SUM(line_item_amount)
	FROM invoice_line_items
	GROUP BY account_number
	WITH ROLLUP;

# 7
SELECT vendor_name, COUNT(DISTINCT li.account_number) as number_of_gl_accounts
	FROM vendors AS v
		JOIN invoices AS i
			ON v.vendor_id = i.vendor_id
		JOIN invoice_line_items AS li
			ON i.invoice_id = li.invoice_id
	GROUP BY vendor_name
		HAVING number_of_gl_accounts > 1
	ORDER BY vendor_name;