How to setup xdebug with Netbeans on Unbuntu

php code

xdebug is a PHP extension for debugging of php code. It supports stack and function traces, profiling information and memory allocation and script execution analysis. It uses the DBGp debugging protocol.  In this post we are going to see easy steps to install and setup it with Netbeans IDE on Ubuntu

Step 1:

Install xdebug using following command

 

Step 2:

Browse to your php folder and locate xdebug.so file. In my case it is /usr/lib/php5/20121212/xdebug.so. Copy this files path.

Step 3:

Open your php.ini ( /etc/php5/apache2/php.ini ) and add following lines at the end of this file

Replace zend_extension path with the path you have copied in previous step

Step 4:

Restart your apache server using

Step 5:

Open Neatbeans and goto Tools > Options > PHP > Debugging and make sure that there is Debug Port set to 9000
and Session ID to “netbeans-xdebug

Step 6:

Thats it you are almost done. Now just create a new php project, add some breakpoints to any php file in it and click on Debug Project from tool bar or press ctrl+F5. This will start debugger.

 

Debugging Magento Project using xdebug with Netbeans on Ubuntu

PHP Script to scan all ports of website or host

php code

Following is PHP code which will scan all ports of particular host / website and will print list of all open ports in result. This code can be use to probe a server or host for open ports. This is often used by administrators to verify security policies of their networks and by attackers to identify services running on a host and exploit vulnerabilities. ports scanning  is a process that sends client requests to a range of server port addresses on a host, with the goal of finding an active port; this is not a nefarious process in and of itself. The majority of uses of a port scan are not attacks, but rather simple probes to determine services available on a remote machine. So I will recommend to use it for making your servers more secure.

PHP code for removing unnecessary whitespaces from html

php code

Removing unnecessary white-spaces and extra characters from html source code, helps for improving overall rendering speed of web page. Specially in browser window. Following is simple PHP script which will remove all unnecessary white-spaces from html source. And thus minify it and improves rendering speed. Add this code in header of your PHP page to see the effect.

 

How to optimize Magento website performance

Magento-ecommerce

Magento if the most widely used e-commerce framework. In this post I have mentioned few important points through which we can optimize overall Magento website’s performance. Most optimizations will work with any version of Magento.  Note that here I assume your customized Magento website is build by following all the recommended coding standards (For more information about Magento coding standards please visit http://devdocs.magento.com/guides/v2.0/coding-standards/bk-coding-standards.html). So, following are important points/guidelines you are supposed to follow to improve Magento performance.

  • Enable Cache through Magento Admin Panel.
  • Use minified js/css and enable Merge CSS/JS through Magento Admin Panel
  • Enable code compilation after complete development. If updates, code modifications, extension installations are needed, code compilation needs to be disabled first. If not, there will be errors.
  • Set HTTP Header Field Connection : Keep-Alive through server configuration.
  • Do not take backup or place other folders in servers “/var/www/html/”  other that project’s main folder.
  • Use PNG images.
  • Apply lazy loading on images.
  • Reduce HTML source code by removing spaces, commented text and make HTML inline, this helps to render page fastly by browser.
  • Enable Flat Categories and Products: In Magento admin, (top menu) System > Configuration, (left nav) Catalog > Catalog, (main page) Frontend.  Set “Use Flat Catalog Category” and “Use Flat Catalog Product” to “Yes“. Attributes that apply to Categories and Products are stored in separate database tables depending on their datatypes. ‘Flattening’ will put all attributes in one table for Magento retrieve. This will have a positive impact on site speed especially if it has 1,000 or more products.
  • Optimize the MySQL server (enable Query Cache and tweak my.cnf parameters).
  • Enable gzip through server configuration and note that you don’t apply it on images as images are already compressed.
  • As part of database maintenance do log cleaning.
  • Use PHP Accelerators : Using a PHP accelerator is another form of caching. They increase performance of PHP scripts by caching them in their compiled state. You can use a PHP accelerator like APC, ZendOptimizer+ or Xcache.

Rules for improving web page response time :
Studies have shown that web page response time can be improved by 25% to 50% by following these rules.

Creating custom category attribute in Magento

Magento-ecommerce

In this short article contains code for creating custom category attribute in Magento . Run this script from your magento root folder and it will create custom attribute of type int in General group. To test whether attribute is created or not Go to your magento admin panel > catelog > manage categories and user General tab you will see Most Popular Products attribute.

 

PHP script for WHOIS Lookup on domain name or IP

php code

This is a PHP script for performing WHOIS lookups on domain name or IP address. This PHP script is intended to lookup for domain registrant data for all top-level domains (both generic and country-code types are supported, 158 TLDs in total), and also for IP whois lookups.

php whois script php whois lookup  whois php code domain whois lookup php script

Generate Excel Sheet in PHP

php code

Hello readers, in this post we are going to see the code to  generate excel sheet in PHP by exporting contents from database i.e., directly outputting your query result to excel sheet (.xls file) and adjusting HTTP header fields

 

PHP script for fetching 4GB file from URL to your Server

       Below is the php script for fetching 4GB file from URL to your Server. The ini_set(‘upload_max_filesize’, ‘5000M’), ini_set(‘post_max_size’, ‘5000M’) statements specifies the maximum size of the data to fetch/upload by the script, if we want to fetch file of size 10GB then we can easily do so simply by changing the 2nd parameter(size in megabytes) of this calls. Next important setting is set_time_limit (24 * 60 * 60) which specifies the maximum time in seconds for running this script  ( as downloading file size is more it takes more time). Note that this time totally depends on the size of the file you want to fetch and the network speed of your server.
         If you are thinking of running this script on general hosting service (where network speed is less) then it requires more time to execute (may be in Hrs) so, accordingly  you should set execution time limit. I had tested it on my local machine as well as on hosting service although it takes more CPU resource but works fine. I recommend to use it only for personal use. Its totally inefficient for bulk fetches, most of hosting services do not recommend such scripts because it simply  overloads their resources.

Continue reading “PHP script for fetching 4GB file from URL to your Server”