Posts

Showing posts from June, 2012

Disadvantages of ORM

ORM has attracted a lot of attention in the last years. So let's get a bit deeper into it. The biggest advantage of ORM is also the biggest disadvantage: queries are generated automatically queries can't be optimized queries select more data than needed, things get slower, more latency (some ORMs fetch all datasets of all relations of an object even though only 1 attribute is read) compiling queries from ORM code is slow (ORM compiler written in PHP) SQL is more powerful than ORM query languages database abstraction forbids vendor specific optimizations Other problems coming up with ORM compiling ORM logic from phpDoc instructions or XML files is slow, but can be cached ORM validates relations and field names outside the database, but can't keep relations consistent ORM libraries are often used in projects without making a benchmark before ORM libraries are often used because the documentation of the library says it is very fast ORM libraries are often used by default with

Things you should not do in PHP (update: references)

Here is a list of things you should not do in PHP. Most of the stuff is pretty obvious, but over the years I've seen a lot of them. In most cases, these problems remain hidden until data grows above 10000 entries. So on a development system, things are always fast and there are no problems with memory limits :-) Suppose we have a table with 100k entries: $db->query('create table stats (c1 int(11) primary key, c2 varchar(255))'); $db->query('begin'); for ($i=0; $i<100000; $i++) { $db->query('insert into stats values ('.$i.','.($i*2).')'); } $db->query('commit'); Populate a big array instead of streaming results: $result = $db->query('select * from stats'); $array = $result->fetch_all(); // 35M // or while ($row = $result->fetch_assoc()) $array[] = $row; // 35M // or while ($row = $result->fetch_array()) $array[] = $row; // 44.5M // process $array ... // instead of: while ($row = $result->fetch

PHP memory consumption with Arrays and Objects (update: generators)

Lessons learned: objects need more memory than arrays (+ 2-10 percent) comparing 32bit to 64bit systems, memory consumption increases by 100-230 percent if array values are numeric, don't save them as strings! saving 1M integers takes 200M of memory with PHP on a 64bit plattform (increase by factor 25) using SplFixedArray can reduce memory usage by 20-130 percent avoid big Arrays and Objects in PHP whenever possible (don't use file('big_file') or explode("\n", file_get_contents('big_file')), etc.) use streams whenever possible (fopen, fsockopen, etc.) use generators when available with PHP 5.5 ( RFC ) If you need to save memory temporarily in your script, you can stringify your array (increasing cpu usage and runtime): $a = array(); for ($i=0; $i<1000000; $i++) { $a[] = $i; } $a = implode(',', $a); // or $a = json_encode($a); echo number_format(memory_get_usage(true)/1048576, 2)."\n"; // 8.0 M (64bit), 7.5 M (32bit) Here is

Managing raw HTML and Razor code in project

Image
Intent of this post ================= This article is about approach for structuring MVC application so as to manage front end  raw HTML design code along with developer's corresponding dynamic razor code Background ================== In general,  following is a flow of an idea to a live page (from design perspective): Now here comes a question:  "How should static HTML code and dynamic Razor code be managed in a solution?" Answer...Depends.......! Case-1 : When developer is the same person who does both front end design and server code, there is no special arrangement required and one physical .cshtml file is enough.  Case-2 : When designers are smart enough to sneak into developer's razor code and implement any UI requirement, again a single file is sufficient. Case-3 : In bigger projects, where exists separate team for Design+HTML code and Razor+Backend code which is bridged by a Manager, there, it is really a good idea to have design HTML exists physically separat

Choosing the Right Web Designer

Creating your web site can be a tricky process. Choosing the best web design company for your site is extremely important. Unless you run a web-based business, you probably do not have web design experience within your company. Building your web site will take time and a little homework! To create a web site for your business, follow these 4 simple steps:    1. Establish your goals    2. Determine your budget    3. Pick a web design company    4. Pick a web hosting company Establish Your Goals Before you begin looking for company to help you design and build your web site, take the time to understand the goals of your web site. This will be extremely important to help set expectations with the web design company you choose. In order to set your web site goals, ask yourself the following questions:     * Why do you want a web site?     * Are you selling something?     * Do you have a catalog of products that changes on a regular basis?     * Who is your target market?     * Do you alrea

Replace Smarty with PHP templates

In many performance guides, Smarty is considered to be removed to speed up things. But oftentimes it's not Smarty causing performance problems, but rather big modifier chains not being cached. To point this out, we need to profile our template which is quite difficult when Smarty compiles in into something unreadable. So we need a quick and easy way to replace the Smarty template engine with pure PHP code. Since Smarty can't do more than PHP, let's replace Smarty with simple PHP templates. So I'm providing here a small guide to replace Smarty with simple PHP based templates. These can be also cached by APC without any compiler. First thing: Smarty configuration files e.g. core.conf foo = bar [core] logo = public/img/logo.png link = http://www.simple-groupware.de notice = Photo from xy bg_grey = #F5F5F5 Now let's convert it to PHP: core_conf.php <?php $config = array( "logo" => "public/img/logo.png", "bg_grey" => &qu

Agenda

Welcome to my first blog! Yes, I'm a bit late in 2012, but I've collected some important things I'd like to write down and analyze in more detail. In the daily IT business, it is often unclear if software should be optimized or better hardware should be ordered. This blog should help you to make this decision easier by looking at the benchmarks of possible software optimizations. Here is a small agenda of the things I'll write in the next weeks: The impact of APC/Optimizer+ APC vs Memcached (local vs distributed cache, refresh, serialization) The power of cache warming How to write a really small and fast AJAX controller with PHP How to write a really small and fast O/R-mapper with PHP How to write a really small and fast CMS Why entity–attribute–value is bad for performance How to benchmark a PHP framework How to find the right PHP framework (or why to write your own) How to implement client side session storage Iteration vs Recursion ...

Top 10 Tips for Choosing a Web Designer for Your Business Web Site

How to Choose a Web Design Firm Simple. You do your homework on them. Then, you start asking questions and taking notes. There are plenty of web designers available. You want to go with the best because, in fact, your web designer is in essence your partner. You want to choose a designer that takes YOUR business seriously. What questions do you ask? There are several important questions to ask when choosing a web designer for your business web site. Creating your web site can be a tricky process. Choosing the best web design firm for your business web site is a very important decision. And if your company is like most small businesses, you probably do not have web design experience. Building your web site will take time and work. And working with a web designer is no easy task. So choose the right web design company from the start and avoid do-over's, which can be costly and time consuming. 1. What kind of web experience do you have? For starters, find out what kind of design exper

A Simple Calculator [Android]

Image
We are going to see how to create a simple calculator for Android platform. This is like a hello-world program and is really easy to do. Please Leave A Reply To Improve The Content Tools we need / that I used : Eclipse with All android plug-ins installed ( How to install? Ans:  Here  ). Android SDK with at least one platform installed (I use Android 4.0.4 ). Prior knowledge required : Well, you need to how Mark-Up language works. At least you should know what is tag and its attributes. Best way to learn, learn HTML. We use XML that doesn't differ much from HTML except for the namespaces, you use android:[attribute] = "" instead of [attribute] = "" A little java on handling the data types and simple castings. How to run apps in android phone. Just click them on the icon :P. How to recommend this tutorial to others : Click the   +1  button at the end STEP I : Starting Your Project Start Eclipse and create a new project ( File -> New -> Project... ). In the

Understand the Timestamp Based Protocol with example

Image
Hi, how are you? In this tutorial I will clarify you the timestamp based protocol with explanation. I think this tutorial may help you to understand the timestamp based protocol easily. Now think the given picture.  This is a picture of real timestamp. Real timestamp show you the time. But database timestamp what is it? Yes, database timestamp is same as real timestamp.  What is a database timestamp? Database timestamp is nothing but it counts the time of any transaction. It builds with sequence of character which show you the time of any transaction. We use the timestamp to compare transaction duration between transaction. So we say that database timestamp is same as the real timestamp but we use these types of timestamp in different purpose. Why we use Timestamp in the database? To compare one transaction to another we use the timestamp. We count the transaction duration using timestamp . If one transaction timestamp is greater than another transaction timestamp. The priority is give