Tips to optimize php code

February 1st, 2008 by ImageLeet-Admin
  1. If a method can be static, declare it static. Speed improvement is by a factor of 4.
  2. echo is faster than print.
  3. Use echo’s multiple parameters instead of string concatenation.
  4. Set the maxvalue for your for-loops before and not in the loop.
  5. Unset your variables to free memory, especially large arrays.
  6. Avoid magic like __get, __set, __autoload
  7. require_once() is expensive
  8. Use full paths in includes and requires, less time spent on resolving the OS paths.
  9. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
  10. See if you can use strncasecmp, strpbrk and stripos instead of regex
  11. str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4
  12. If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
  13. It’s better to use select statements than multi if, else if, statements.
  14. Error suppression with @ is very slow.
  15. Turn on apache’s mod_deflate
  16. Close your database connections when you’re done with them
  17. $row[’id’] is 7 times faster than $row[id]
  18. Error messages are expensive
  19. Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.
  20. Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.
  21. Incrementing a global variable is 2 times slow than a local var.
  22. Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.
  23. Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
  24. Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.
  25. Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.
  26. Methods in derived classes run faster than ones defined in the base class.
  27. A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.
  28. Surrounding your string by ‘ instead of ” will make things interpret a little faster since php looks for variables inside “…” but not inside ‘…’. Of course you can only do this when you don’t need to have variables in the string.
  29. When echoing strings it’s faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.
  30. A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.
  31. Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.
  32. Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request
  33. When working with strings and you need to check that the string is either of a certain length you’d understandably would want to use the strlen() function. This function is pretty quick since it’s operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.
  34. When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don’t go modifying your C or Java code thinking it’ll suddenly become faster, it won’t. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend’s PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.
  35. Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.
  36. Do not implement every data structure as a class, arrays are useful, too
  37. Don’t split methods too much, think, which code you will really re-use
  38. You can always split the code of a method later, when needed
  39. Make use of the countless predefined functions
  40. If you have very time consuming functions in your code, consider writing them as C extensions
  41. Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview
  42. mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80%

Posted in Tutorials | No Comments »

35 reasons to choose linux over windows

February 1st, 2008 by ImageLeet-Admin

 

Linux

           Core OS Features:

  1. Linux doesn’t have the virus problems. Evenmicrosofts stevebalmer couldnt clean windows viruses . Still not convinced? . Its not that there aren’t any viruses for Linux but Linux is more secure and less virus prone.

  2. Linux Doesn’t need defragging. The Linux file systems work very efficiently such that it arranges data in a way that it doesn’t require defragging. to know more, read earlier post.

  3. Linux doesn’t crash without any apparent reasons.In Linux the core operating system (kernel) is separate from the GUl (X-Window) from the applications (OpenOffice.org, etc). So even if the application crashes, the core operating system is not affected. In Windows (Microsoft prefers to call this tight integration) if the Browser crashes, it can take down the entire operating system.

  4. Linux doesn’t require frequent re-installation. In Windows if the OS crashes, there is no easy way to recover this. Many IT support staff don’t know what to do and all they can do is re-install Windows. Which means that users applications and preferences are lost, and again needs to be installed. I haven’t seen anyone using Linux, requiring to re-install unless there is a hard drive failure. Most things in Linux can be fixed without requiring re-installation. The benefit of this is all the users preferences can be preserved even if the OS needs to be re-installed. This can be handled by creating a separate partition for the home directory.

  5. Linux doesn’t require frequent rebooting. Linux runs extremely stable, even if an application crashes, there is no need to reboot the whole system, just restart that application or service.

  6. Linux can read over a 100 different types of file systems.. Windows is limited to its own two file systems. Well most general users may not care about this but its extremely useful is you are working in a mixed environment or you need to extract some data from a hard drive formatted on another computer.

  7. You have the source code and the right to modify or fix things if you are a programmer. Many end users think this is not necessary but they will realize how important this is when their application vendor decides to discontinue support on a older version to promote a newer one.

  8. Linux can install in logical partition or a second (slave hard drive as well)Windows can only be installed in a primary partition.

  9. Linux is scalable right from the PDA/Cellphones to super computers.

  10. Linux is running mission critical applications including powering an aircraft.

  11. Linux has less bugs than commercial software, this is one of the main reasons for its stability.

  12. You can also share the software with your friends and its completely legal to do so. Didn’t your teacher tell you in kindergarten that you should share things with your friends? Linux and Open Source actually encourage that while if you do that in Windows its not only considered illegal but they will call you a pirate!

  13. Linux costs less, cause not only the OS is free but the applications are also free. Plus since Linux doesn’t have a virus problem, you also save on the recurring cost of Anti-Virus software. Note: You may still have to pay for support/training but the over all running cost is low.

  14. Both Linux and Windows has shell environment Windows (know as command prompt). The shell environments in Linux (such as bash) are more powerful and you can write entire programs using the scripting language. This is extremely useful to automate repetitive tasks such as backup.

  15. Linus can run from a CD or can be installed on the hard drive. Windows by default doesn’t have any such option. Using live CDs such as Knoppix, users can try out Linux by booting from the CD, without the need to install the operating system.

  16. Did you know that in Windows, there is built in back-door entry so US government can see you data as and when they like? Yes the US NSA has the key build into every copy of Windows. In Linux there is no such thing possible as the operating system is open source and can easily be detected and disabled.

  17. Linux has built in virtualization(XEN) so you can run multiple copies of Linux or other operating systems simultaneously.

  18. The Linux kernel comes shipped with an enormous load of hardware drivers. On Windows, a lot of hardware doesn’t work until you install the driver, this problem is worse with Vista. On Linux, a huge percentage of today’s common hardware works perfectly out-of-the-box.

  19. While both Linux and Windows have a GUI, Windows has only one default GUI. Linux is all about choice and has a option to use different type of GUIs or Window Managers as they are know as in Linux. Users can choose from something that looks like their favorite Operating System or they can choose something that’s simple and fast.

  20. Most Linux distributions come bundled with whole lot of applications such as Office Suite, Photo Editing, etc. You not only get the OS for free but you also don’t have to pay for the applications. Yes many of these open source applications such as OpenOffice.org also run on Windows but you need to find, download and install them where as there are available in most Linux distros by default.

  21. Expanding on the previous point, many Linux distributions bundle thousands of applications (6,000-10,000 depending on which one you choose) where as Windows doesn’t bundle basic applications such a decent text editor, oh yeah there is Notepad if you consider that decent. Point is spend the time in finding them, downloading them, installing them and then trying them out on Windows or just get them along with your Linux DVD.

  22. Linux bundles OpenOffice.org as the office suite which has built in capabilities to write documents/presentations as PDFs and Flash. Windows requires purchasing/downloading additional software.

  23. Mozilla Firefox browser bundled with Linux has excellent features such as blocking of unwanted ads/pop up and supports tab browsing which makes it easy to open another browser windows.

  24. Browsing is not only better but faster too! The networking on Linux is faster and the browser has an option to block all the unwanted ads/pop up, there by saving on bandwidth considerably. .

  25. Linux has games too! there are some really nice games which many of the Linux distributions bundle. You may not have all the games in the world but you definitely have a huge collection of free games.

  26. Gaim/Kopete popular IM clients on Linux are single clients that can connect to all the protocols - Yahoo, MSN, Jabber, ICQ, AOL and more. Gaim is also available for Windows for people who are still using Windows.

  27. Cut and paste is simpler, just select and middle click on the target window and your data gets pasted. Its far quicker and easier than the way Windows does Cut and Paste. Ofcourse the Windows CTRL-C/CTRL-V still works on Linux for people who are still new.

  28. Easy to setup a Media Center like PC. You don’t need to purchase additional software or re-install a different operating system.

  29. Linux already has a usable 3D Desktop - XGL. This makes it easy to switch and view multiple desktops simultaneously.

  30. Multiple cut and pastes. Klipper application (default under KDE) maintains a history of your clipboard and you can use it to paste text/etc which you had cut/copied earlier.

  31. Graphic view of how much space your data is using. In Konqueror File Manager tool bar, there is an option to get file size view which gives you a graphical view of how much space your directories and the files within are consuming. This is an excellent way to know where all your disk space has disappeared and makes cleanup easy.

  32. Server Side features:

  33. Linux has bundled Databases such as MySQL and PostgreSQL which are extremely powerful and used in production environments. Customer doesn’t need to purchase expensive databases.

  34. Linux is been used for super computing cluster, most of top super computers in the World use Linux. Windows just can’t scale to that level.

  35. File system scalability, while NTFS file system can scale upto 16TB, XFS on Linux can scale upto a million TB! yes that bigger than what you would ever need.

  36. Processor scalability: Linux can scale to 1024 processors on a single computer! Windows can’t even claim to come anywhere near that number.

Posted in others | No Comments »

Mediterranean cable break disrupts communications with Asia

January 31st, 2008 by ImageLeet-Admin

Internet service is disrupted more than 50 percent across the entire Middle East. The outages are caused by two submarine cable systems in the Mediterranean Sea which were cut, apparently by accident by ship anchors. India suffered up to 60 percent disruption, while 70 percent of the nationwide network in Egypt is down, news agencies reported.

Similar shortages occurred in the United Arab Emirates (UAE), Kuwait, Bahrain, Qatar and Saudi Arabia. “It’s a national disaster,” said Joseph Metry, network supervisor at Orascom Telecom Holding SAE, the biggest mobile- phone company in the Middle East and North Africa, as quoted by Bloomberg News.

The cable system which was cut somewhere 5.2 miles from Alexandria beach in northern Egypt was co-owned by several companies, among which AT&T Inc., the biggest U.S. phone company, and Verizon Communications Inc., the second-biggest U.S. phone company. Customers of both companies were affected.

Currently, telecommunications companies are rerouting traffic through other connections which will lead to congestions at peak hours.

“There has been a 50 to 60 per cent cut in bandwidth,” Rajesh Chharia, the President of Internet Service Providers Association of India confirmed to India Today.

Repairs may take up to two weeks. It is still unknown what actually happened, because undersea cables are very strong, shielded with several layers of steel.

“Despite this being an international cable affecting many Gulf and Arab countries, we are closest to it and so we have a lot of responsibility,” said Egyptian telecommunications expert Rafaat Hindy to AP. “We are working as fast as we can.”

A modern undersea or submarine communications cable is made up of a core of optical fibers, shielded with multiple layers of copper, aluminum, polycarbonate, stranded steel wires, Mylar and polyethylene. The first undersea cables were used for telegraph and were laid in the second half of the nineteenth century. As of 2003, submarine cables link all the world’s populated continents.

Posted in News | No Comments »

Garmin First handset nuviphone announced

January 31st, 2008 by ImageLeet-Admin

Last night at a secret event, Garmin, best known for its GPS receivers, announced its first foray into the mobile phone arena. The Garmin Nuviphone is a full touch based device with a large 3.5″ touchscreen and integrated GPS. Other features include a camera with video recording and support for HSDPA high-speed 3G networks. This UMTS/GSM handset is planned to be available in the third quarter of 2008, but pricing has not been announced.

Garmin has not released technical specifications, but they have announced some innovative software features that are sure to impress. The Nuviphone, when placed in its vehicle mount, will automatically turn on the GPS receiver and switch to navigation mode, transferring any active calls to handsfree mode. The GPS navigation will include Garmin Online, which provides easy access to local traffic information, gas prices, and hotel rate information.

Photos taken with the built-in camera will automatically be geo-tagged with location data, so that users can visually browse through their landmarks. Google is also a big partner, adding its integrated local search capabilities, as well as access to Google’s Panoramio library, with snapshots of landmarks tagged with location information.

Posted in Gadgets | No Comments »

About this blog

January 31st, 2008 by ImageLeet-Admin

ImageLeet is Proud to present you the official IL blog. Purpose of this blog is to keep you updated about latest developements in the company and services being offered at the latest. Blog will be more than the average hosting industry news posts and would introduce technologies from different stream on the slots.

Posted in News | No Comments »

Next Entries »