Open source projects can sometimes be a bit of a pain in phpStorm.
Here I am going to show how to fix code completion for CodeIgniter in phpStorm.
Common Issues
January 29th, 2012
Open source projects can sometimes be a bit of a pain in phpStorm.
Here I am going to show how to fix code completion for CodeIgniter in phpStorm.
Common Issues
January 26th, 2012
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
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.
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,
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.
December 11th, 2009
I have been getting deeper into development with Word Press, mostly styling but none the less working in Word Press because the fact of the mater is that there is a market for it. The point of this post is this, building a dynamic site can get quite heave very quickly, especially in WP. If you add a bunch of plug-ins which are loaded dynamically then add a custom theme that you maybe even paid a premium price for, your database queries can go through the roof.
For instance, WP has like 9 queries on an empty page with no plug-ins, that’s a lot already. Now add one of the themes out there with a couple rows of featured posts blocks. One thing that I noticed looking through some of these fancy themes is that they are running a ton of queries to get these featured posts.
Add 3 rows of 3 and a couple plug-ins and you are well over 50 queries.
Now have 100 visitors at a given moment on that page, that is a minimum of 5000 database calls in that moment.
You had better have an excellent host!
I’ve also seen this with dynamic Ajax scroll-er plug-ins.
3 posts to grab content from in one category and its 7-9 queries. Something is not right there, guys.
You should be able to grab that content in 2 queries, 1 if the database structure was descent (but that’s a whole different game).
For you out there with front pages like this, do yourself a favor, especially if you have had issues in the past.
See how many queries are loading and how long it takes, it’s simple to do.
In your theme’s footer.php template before the closing
</body>
Add
| Select All | |
|---|---|
1 | <?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds. |
Now your pages will show you how many queries there are for each page.
You can determine what to do from there.
As a further note on the subject, you can have a featured content page and have a bunch of blocks and not have it take a bunch of database queries.
Stay Tuned and I might tell how