‘Web Development’ Category

phpStorm Logo I use phpStorm pretty much exclusively for PHP development, for over a year.
It simply has some awesome features.

But there are some things that people tend to complain about.
One of the biggest I am going to show you how to fix.

phpStorm by Jetbrains uses a stricter approach for code completion than most PHP IDE’s.
They index all constructs but for everything else phpStorm requires proper phpDoc annotations.

The reason behind this I think is simply for performance to keep it a bit litter and to have faster start-ups.

I will be doing a few of these examples for popular open source projects that have code completion issues do to their standards or simply not having phpDocs at all.

Once you get the hand of this, its pretty easy to do and works quite well.
Some of these issues are seen in all IDE’s not just phpStorm

So here we go, digging into the code.
The comments explain just about everything you need to know.

Select All
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* @see https://gist.github.com/1105126
*/
 
// Also some more hints and fixes
 
// WP functions for adding to the admin bar
// This will provide code completion for admin_bar functions like add_menu()
/** @var $wp_admin_bar WP_Admin_Bar */
global $wp_admin_bar;
 
// Fixing dynamic includes, also so they link properly in the editors environment
require_once(get_template_directory() . '/inc/base.php');
//As is the above require will show an error in phpStorm "Cant resolve target....."
 
//To fix this is easy, this fixes the error and also allows control click on the base.php and opens it
/** @define "get_template_directory()" "/var/www/wp-dev/wp-content/themes/tridium" This is just for the IDE */
require_once(get_template_directory() . '/inc/base.php');
 
// These same methods can be used to fix most errors and completion in phpStorm

Basically for accessing WordPress’s functions and methods that are mostly used eg wpdb, you add this file to the WP root https://gist.github.com/1105126.

I prefer as in the comments of the file to have the class named wpdb and remove the extends.
Like this,

Select All
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
 * @property wpdb  $ID
 * @property wpdb  $post_author
 * @property wpdb  $post_date
 * @property wpdb  $post_date_gmt
 * @property wpdb  $post_content
 * @property wpdb  $post_title
 * @property wpdb  $post_excerpt
 * @property wpdb  $post_status
 * @property wpdb  $comment_status
 * @property wpdb  $ping_status
 * @property wpdb  $post_password
 * @property wpdb  $post_name
 * @property wpdb  $to_ping
 * @property wpdb  $pinged
 * @property wpdb  $post_modified
 * @property wpdb  $post_modified_gmt
 * @property wpdb  $post_content_filtered
 * @property wpdb  $post_parent
 * @property wpdb  $guid
 * @property wpdb  $menu_order
 * @property wpdb  $post_type
 * @property wpdb  $post_mime_type
 * @property wpdb  $comment_count
 * @property wpdb  $filter
 * @property wpdb  $term_id
 * @property wpdb  $name
 *
 */
class wpdb {}

Then I drop that file in the WP root.
phpStorm will index the construct and use the listed properties in that file for code completion within the wpdb class.

You should not get duplicate class errors because we are not instantiating it.
Its just there for phpStorm.

I will be doing one of these for phpBB3 and also CodeIgniter so you may want to subscribe and follow future posts.

August 17th, 2011

BenchMark Limbo with ORMs

So the story goes like this….

I have been building a business model and planning out a SaaS application for a future company I am building.

In the process I have been looking at frameworks, ORMs, DBALs, etc… to speed up the build process.

At the same time I have had some concerns.

  1. Memory usage
  2. Process usage
  3. Load time
  4. Learning curve

Learning curve being the smallest issue since all any of the above  (quick build options) are just OOP PHP, but none the less you have to learn their code.

So I have really been struggling with this part. Use quick build options, don’t use them????

So today I decided to do a quick benchmark, nothing special, just load time and memory usage.

I have a MySQL database with 240,000 records in it.

I chose to use Propel ORM because I really like it, but the following benchmark has me in limbo bit…

KEEP in mind, this is not a competition between ORMs or frameworks.

This is just between an ORM which I chose Propel and raw PHP –> MySQL.

Here is the outcome of the benchmarks,

———————————————————————-
ORM results Propel Hydration Demand was used.
———————————————————————-

20,000 Records, APC Opcode Cache on
Load Time: 4.040 seconds. • Memory Usage: 1.03 MiB
Peak Memory Usage: 1.050041 MiB

100,000 Records, APC Opcode Cache on
Load Time: 17.985 seconds. • Memory Usage: 1.03 MiB
Peak Memory Usage: 1.050362 MiB

100,000 Records, APC Opcode Cache off
Load Time: 17.936 seconds. • Memory Usage: 3.32 MiB
Peak Memory Usage: 3.344589 MiB

———————————————————————-
           Raw code
———————————————————————-

20,000 Records, APC Opcode Cache on
Load Time: 0.916 seconds. • Memory Usage: 0.33 MiB
Peak Memory Usage: 0.355274 MiB

100,000 Records, APC Opcode Cache on
Load Time: 2.392 seconds. • Memory Usage: 0.33 MiB
Peak Memory Usage: 0.355274 MiB

100,000 Records, APC Opcode Cache off
Load Time: 2.161 seconds. • Memory Usage: 0.33 MiB
Peak Memory Usage: 0.355274 MiB

So the results are a bit twisted. Was not what I was expecting, higher memory Yes, load time I thought would have been way better.

Also NOTE that this is not an application being benchmarked, it is just one query grabbing records from one table!

While 3.3MG of memory is not a lot to worry about, consider you still need all of your application code which will be more code than the ORM.
18 seconds to collect the data, well, thats just disappointing!

Where do I go from here? Well, I’m not sure.

This application will be huge and have what is planned a large user base.

Saving on resources, load time and scaling is KEY.

I know I can build a simple DBAL that will out perform the above ORM results, so I think that is the direction to take.

What I have found out is that ORM’s and FrameWorks are specifically for rapid development.

If I am going to chew up resources with them on a large scale application, then it is not worth using it.

Using some ideas from certain areas is about as far as I can go for this app, the rest will have to be hand written PHP that will be used in the app.

As a side note, notice the results have APC Opcode Cache on/off, APC Opcode Cache is awesome :)

I think ORMs like Propel and Frameworks like CodeIgniter which I really like both and they have a place in development.

If the application has a scaling limit, then thats where I would use them.

But I don’t think this app is the place.

I see a ton of theme builders sprouting out of the woodwork everyday.
The problem is a lot of them have great ideas about the design, but the big part (coding) is terrible.

So here are the top 5 mistakes I see in themes, especially WordPress themes..
Read More…

October 6th, 2010

SEO and Internet Marketing

1286400493_Stats I have not been around much because I have been further investigating Internet Marketing and Search Engine Optimization. They tend to go hand in hand in most situations if not all.

Now being a web developer I was always quite versed in SEO and especially the core of it Keywords and have code semantically correct.

What I have not spent a lot of time on until the last couple months is the actual analysis of it all. Competition, the actual keywords, tracking of the keywords to see the trends and even go as far as testing the different testing techniques. Most of it I all ready used in practice but my resent studies have helped me tune my ways of analysis.

Also something to note is that some of the best tools out there are free tools from Google.

Keyword Research The starting point for finding keywords.

Google Search Is genuinely the starting point.

Google Analytics You can fine tune this wonderful tool to do all sorts of tracking if you spend some time on investigating what it has to offer.

Google Webmaster Tools

We did not even tap into paid systems and tools. These are just the simple necessities and Free.

Something that I have been playing with is Google Analytics and all that it has to offer. I am actually building a bunch of new features into my custom WordPress Framework that will leverage a large amount of the Analytics features that most people don’t even know are there.

Keep in mind the newest kid on the block Bing, they also have a full Webmaster Toolbox. I will get into that on the next SEO / IM article.

August 11th, 2010

Easy Mobile Site with CSS3

CSS3 brings sites to mobile comfortably.

One requirement that is becoming hugely popular in web development is mobile device support.

One of the biggest issues with sites on mobiles is bandwidth.
A lot of it is contributed to the sites style alone.
This can be resolved with CSS3, at least on Android and iPhone.
I tested them myself.
Of course, I doubt Windows Mobile will handle it as IE does not. Maybe the upcoming IE9 will.

On with the code!

To make a site have an alternate theme for the above mentioned phones and maybe others is simple.
No JavaScript required.

Simply make a CSS stylesheet, name it anything, eg. mobile.css
Now in this file you overwrite the widths of the site (main box model blocks).
Making them a max-width of less than 480px.
Make sure you count your padding in there.

In the example I am going to show, I also increase the navigation size for ease on touch screen devices.
I also increase the overall font size. This is easy if you use a Typographic scale like I do. (You will see this also)

Now link in the mobile styesheet with the CSS media=”" property.
In CSS3 you can now use it like this

Select All
1
media="only screen and (max-width: 480px), only screen and (max-device-width: 480px)"

The first part only screen and (max-width: 480px) works nicely so we can test it on our desktops in FireFox, Safari, Chrome… Not IE..
The second part , only screen and (max-device-width: 480px) is a device detection eg.(mobile device).

So this complete line linking to the mobile.css will look like this

Select All
1
<link href="mobile.css" media="only screen and (max-width: 480px), only screen and (max-device-width: 480px)" rel="stylesheet" type="text/css">

Add this after you normal CSS linked file so it overwrites it when used.

One other thing we need is a meta tag required for some mini browsers.
The tag looks like this

Select All
1
<meta name="viewport" content="width=device-width" />

Add this line to the top of your sites header by the other meta tags before your CSS links.

Here is a working sample
CSS3 Mobile Device Site Sample
View it in your browser and reduce the browser width to 480px or less and you will see it change.
Or view it in an iPhone or Android phone.

I also included links in this sample to the source code so you can see the code in full.
Here they are again
Index Source
StyleSheet
Mobile Stylesheet

Conclusion:

With simple options like this you can make a lightweight version of any site for these devices.
Simple overwriting backgrounds, CSS image links, etc…..

Nice simple solution with no extra URL re-writes or JavaScripts for detection…
We can only hope this will be fully adopted to all Mobile HTML browsers, and soon.