November 28

Query Optimization

Below are some tips, using which we can optimise the mysql queries.

  • Use EXPLAIN to determine queries are functioning appropriately.
  • Test your queries often to see if they are performing optimally
  • Use GROUP BY instead of DISTINCT when appropriate.
  • Use indexed columns in WHERE, GROUP BY, and ORDER BY clauses
  • Use a LIMIT on UNION instead of OR for less than 5 indexed fields.
  •  Use a indexed field and ORDER BY instead of MAX.
  • Avoid using ORDER BY RAND().
  • Minimize the data in your query to only the data you need, using * is overkill most of the time.
  • Consider persistent connections instead of multiple connections to reduce overhead.
November 26

InnoDB vs MyISAM

The 2 major types of table storage engines for MySQL databases are InnoDB and MyISAM. To summarize the differences of features and performance,

 

  1. InnoDB is newer while MyISAM is older.
  2. InnoDB is more complex while MyISAM is simpler.
  3. InnoDB is more strict in data integrity while MyISAM is loose.
  4. InnoDB implements row-level lock for inserting and updating while MyISAM implements table-level lock.
  5. InnoDB has transactions while MyISAM does not.
  6. InnoDB has foreign keys and relationship constraints while MyISAM does not.
  7. InnoDB has better crash recovery while MyISAM is poor at recovering data integrity at system crashes.
  8. MyISAM has full-text search index while InnoDB has not.

In light of these differences, InnoDB and MyISAM have their unique advantages and disadvantages against each other. They each are more suitable in some scenarios than the other.

November 20

cURL

cURL is a library that lets you make HTTP requests in PHP. Everything you need to know about it (and most other extensions) can be found in the PHP manual. In order to use PHP’s cURL functions you need to install the » libcurl package. PHP requires that you use libcurl 7.0.2-beta or higher.

 

For basic curl example, click here

Category: curl | LEAVE A COMMENT
November 19

Error Levels in PHP

php-error

Error Level Value Description
E_ERROR 1 A fatal run-time error, that can’t be recovered from. The execution of the script is stopped immediately.
E_WARNING 2 A run-time warning. It is non-fatal and most errors tend to fall into this category. The execution of the script is not stopped.
E_PARSE 4 The compile-time parse error. Parse errors should only be generated by the parser.
E_NOTICE 8 A run-time notice indicating that the script encountered something that could possibly an error, although the situation could also occur when running a script normally.
E_CORE_ERROR 16 A fatal error that occur during the PHP’s engine initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
E_CORE_WARNING 32 A non-fatal error that occur during the PHP’s engine initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
E_COMPILE_ERROR 64 A fatal error that occur while the script was being compiled. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
E_COMPILE_WARNING 128 A non-fatal error occur while the script was being compiled. This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
E_USER_ERROR 256 A fatal user-generated error message. This is like an E_ERROR, except it is generated by the PHP code using the function trigger_error() rather than the PHP engine.
E_USER_WARNING 512 A non-fatal user-generated warning message. This is like an E_WARNING, except it is generated by the PHP code using the function trigger_error() rather than the PHP engine
E_USER_NOTICE 1024 A user-generated notice message. This is like an E_NOTICE, except it is generated by the PHP code using the function trigger_error() rather than the PHP engine.
E_STRICT 2048 Not strictly an error, but triggered whenever PHP encounters code that could lead to problems or forward incompatibilities
E_RECOVERABLE_ERROR 4096 A catchable fatal error. Although the error was fatal, it did not leave the PHP engine in an unstable state. If the error is not caught by a user defined error handler (see set_error_handler()), the application aborts as it was an E_ERROR.
E_DEPRECATED 8192 A run-time notice indicating that the code will not work in future versions of PHP
E_USER_DEPRECATED 16384 A user-generated warning message. This is like an E_DEPRECATED, except it is generated by the PHP code using the function trigger_error() rather than the PHP engine.
E_ALL 32767 All errors and warnings, except of level E_STRICT prior to PHP 5.4.0.

 

Category: PHP | LEAVE A COMMENT