Friday, March 29, 2013

Fatal error: Allowed memory size in wordpress


When you install of word press and word press plugin of admin section.
if you facing problem  "Fatal error: Allowed memory size of 33554432 bytes exhausted".



This type error message show 


  1. Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 15552 bytes)in /home/mydomainusername/public_html/blog_wp/wp-includes/media.php on line 253
  2. Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/mydomainusername/public_html/blog/wp-admin/admin-header.php on line 126



Following Point solved "Fatal error" problem .


1. If you have access to your PHP.ini file, change the line in PHP.ini
If your line shows 32M try 64M:
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)

2. If you don't have access to PHP.ini  file , Please try adding this to an .htaccess file:
php_value memory_limit 128M

3. Try adding this line to your wp-config.php file:
Increasing memory allocated to PHP
define('WP_MEMORY_LIMIT', '128M');

4. Talk to your server  host.


 I finally got this problem fixed! using Following below instruction

Very easy handing user end!
if you not got "php.ini" in  "wp-admin" . you  Create a file called "php.ini" in the "wp-admin" folder of wordpress install. 
Add the following text to the file;
memory_limit = 256M ;







What are the difference between DDL, DML DCL and TCL commands?

Following difference between DDL, DML DCL and  TCL commands



Data definition language(DDl)
DDL statements are used to build and modify the structure of your tables and other objects in the database. When you execute a DDL statement, it takes effect immediately.

  1. CREATE - to create objects in the database
  2. ALTER - alters the structure of the database
  3. DROP - delete objects from the database
  4. TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
  5. COMMENT - add comments to the data dictionary
  6. RENAME - Rename an object/Table

Data Manipulation Language(DML)
DML statements are used to work with the data in tables. When you are connected to most multi-user databases (whether in a client program or by a connection from a Web page script), you are in effect working with a private copy of your tables that can’t be seen by anyone else until you are finished (or tell the system that you are finished). You have already seen the SELECT statement; it is considered to be part of DML even though it just retreives data rather than modifying it.

  1. SELECT - retrieve data from the a database
  2. INSERT - insert data into a table
  3. UPDATE - updates existing data within a table
  4. DELETE - deletes all records from a table, the space for the records remain
  5. MERGE - UPSERT operation (insert or update)
  6. CALL - call a PL/SQL or Java subprogram
  7. EXPLAIN PLAN - explain access path to data
  8. LOCK TABLE - control concurrency
Data Control Language (DCL)
DCL is Stand for  Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

  1. GRANT - gives user's access privileges to database
  2. REVOKE - withdraw access privileges given with the GRANT command

Transactional Control Language(TCL)
TCL is Stand for Transactional Control Language. It is used to manage different transactions occurring within a database.
  1. COMMIT - save work done
  2. SAVEPOINT - identify a point in a transaction to which you can later roll back
  3. ROLLBACK - restore database to original since the last COMMIT
  4. SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use 
 ROLLBACK is used for revoking the transactions until last commit.
COMMIT is used for commiting the transactions to the database.
Once we commit we cannot rollback. Once we rollback we cannot commit.
Commit and Rollback are generally used to commit or revoke the transactions that are with regard to DML commands.



NOTE:
DML commands can't be rollback when a DDL command is executed immediately after a DML. DDL after DML means "auto commit". The changes will return on disk not on the buffer. If the changes return on the buffer it is possible to rollback not from the disk


Monday, March 25, 2013

Output Buffering using php


PHP - Caching Pages with Output Buffering

There are 3 Following  basic functions you can use It.


ob_start() any output will be saved in PHP's internal buffer and not yet printed to the screen. This includes HTML and echoed or printed php statements. Header statements are the exception as they are still sent to the browser.


<?php
ob_start(); // Turns on output buffering
?> 



 ob_get_contents() will return a string value of the current contents of the buffer. This will prove very useful for caching purposes when placed at the end of pages. More on that in a bit.



<?php
// Stores the contents of the buffer in a variable as a string
$contents = ob_get_contents();
?>


 ob_end_flush() will print all the contents of the buffer just as you would expect to see it if output buffering was never turned on.


<?php
ob_end_flush(); // Turn off buffering and print the contents
?> 

How to Clear Browser Cache Using HTML CODE or PHP CODE

we have  clear the browser cached page or to force the browser to re-download the content of a page, you can use  the following HTML code in the header tags (<head>) of the page. This code will ask the browser to ignore any saved copies of the page, and to re-download page content.



HTML CODE Before used Head Tag 

<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
<!-- end no cache headers -->

If you doing  work with PHP, you can do the exact same using this PHP code:

PHP Code:

header ("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");  
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
header ("Cache-Control: no-cache, must-revalidate");  
header ("Pragma: no-cache");

Thursday, March 21, 2013

Difference between for and for each loop..?


They works almost same way and same speed as foreach loop will takes time for getting next element while iterating array while for loop will takes time to re-initialize the variable.Following Difference  for and for each loop.


  1. For can be used to run statements for a fixed number of times, 
    Foreach can be used to run statements for dynamically generated arrays(may be result of database query).We can also used for loop for dynamically generated array(may be result of database query). Foreach is the ideal way to iterate dynamic array. The reason behind this, we don't know the index of array as it may be associate result from database query. So if we use foreach than it will iterate the result one by one. 
  2. Foreach will works only and only with arrays.
    For will works for any logical operation and i will continue until given condition fails.There is not much execution time difference.

  3. For loop can be more optimized if we know the count of array and index of array.
    Foreach is better when we have dynamic array without knowing index of array and size of an array.
  4. For loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false. there is need to specify the loop bounds( minimum or maximum).
    int k = 0;
    for (int i = 1; i <= 5; i++) 
    { 
    k = k + i ; 
    }



    Foreach statement repeats a group of embedded statements for each element in an array or an object collection.you do not need to specify the loop bounds minimum or maximum.
    int k = 0;
    int[] tempArr = new int[] { 0, 1, 2, 3, 5, 8, 13 }; 
    foreach (int i in tempArr ) 
    { 
    k = k+ i ; 
    }

Tuesday, March 19, 2013

Speed Up Mysql Queries

You have Given  Tips Using Speed Up  Mysql Queries/Database . Following point remember using mysql query.

  • Use persistent connections to the database to avoid connection overhead.
  • Check all tables have PRIMARY KEYs on Columns/Fields with high cardinality (many rows match the key value). Well,`gender` column has low cardinality (selectivity), unique user id column has high one and is a good candidate to become a primary key.
  • All references between different tables should usually be done with indices (which also means they must have identical data types so that joins based on the corresponding Columns/Fields will be faster). Also check that fields that you often need to search in (appear frequently in WHERE, ORDER BY or GROUP BY clauses) have indices, but don’t add too many: the worst thing you can do is to add an index on every column of a table (I haven’t seen a table with more than 5 indices for a table, even 20-30 Columns/Fields big). If you never refer to a column in comparisons, there’s no need to index it.
  • Using simpler permissions when you issue GRANT statements enables MySQL to reduce permission-checking overhead when clients execute statements.
  • Use less RAM per row by declaring Columns/Fields only as large as they need to be to hold the values stored in them.
  • Use leftmost index prefix — in MySQL you can define index on several Columns/Fields so that left part of that index can be used a separate one so that you need less indices.
  • When your index consists of many Columns/Fields, why not to create a hash column which is short, reasonably unique, and indexed? Then your query will look like:
  • Consider running ANALYZE TABLE (or myisamchk --analyze from command line) on a table after it has been loaded with data to help MySQL better optimize queries.
  • Use CHAR type when possible (instead of VARCHAR, BLOB or TEXT) — when values of a column have constant length: MD5-hash (32 symbols), ICAO or IATA airport code (4 and 3 symbols), BIC bank code (3 symbols), etc. Data in CHAR Columns/Fields can be found faster rather than in variable length data types Columns/Fields.
  • Don’t split a table if you just have too many Columns/Fields. In accessing a row, the biggest performance hit is the disk seek needed to find the first byte of the row.
  • A column must be declared as NOT NULL if it really is — thus you speed up table traversing a bit.
  • If you usually retrieve rows in the same order like expr1, expr2, ..., make ALTER TABLE ... ORDER BY expr1, expr2, ... to optimize the table.
  • Don’t use PHP loop to fetch rows from database one by one just because you can — use IN instead,
  • Example: SELECT * FROM `tableNAME` WHERE `id` IN (27,7,17,1,3);
  • Don’t use REPLACE (which is DELETE+INSERT and wastes ids): use INSERT … ON DUPLICATE KEY UPDATE instead (i.e. it’s INSERT + UPDATE if conflict takes place). The same technique can be used when you need first make a SELECT to find out if data is already in database, and then run either INSERT or UPDATE. Why to choose yourself — rely on database side.
  • Tune MySQL caching: allocate enough memory for the buffer (e.g. SET GLOBAL query_cache_size = 1000000) and define query_cache_min_res_unit depending on average query resultset size.
  • Use column default value, and insert only those values that differs from the default. This reduces the query parsing time.
  • Use INSERT DELAYED or INSERT LOW_PRIORITY (for MyISAM) to write to your change log table. Also, if it’s MyISAM, you can add DELAY_KEY_WRITE=1 option — this makes index updates faster because they are not flushed to disk until the table is closed.
  • Think of storing users sessions data (or any other non-critical data) in MEMORY table — it’s very fast.
  • For your web application, images and other binary assets should normally be stored as files. That is, store only a reference to the file rather than the file itself in the database.
  • If you have to store big amounts of textual data, consider using BLOB column to contain compressed data (MySQL’s COMPRESS() seems to be slow, so gzipping at PHP side may help) and decompressing the contents at application server side. Anyway, it must be benchmarked.
  • If you often need to calculate COUNT or SUM based on information from a lot of rows (articles rating, poll votes, user registrations count, etc.), it makes sense to create a separate table and update the counter in real time, which is much faster. If you need to collect statistics from huge log tables, take advantage of using a summary table instead of scanning the entire log table every time.
  • Divide complex queries into several simpler ones — they have more chances to be cached, so will be quicker.
  • Group several similar INSERTs in one long INSERT with multiple VALUES lists to insert several rows at a time: quiry will be quicker due to fact that connection + sending + parsing a query takes 5-7 times of actual data insertion (depending on row size). If that is not possible, use START TRANSACTION and COMMIT, if your database is InnoDB, otherwise use LOCK TABLES — this benefits performance because the index buffer is flushed to disk only once, after all INSERT statements have completed; in this case unlock your tables each 1000 rows or so to allow other threads access to the table.
  • When loading a table from a text file, use LOAD DATA INFILE (or my tool for that), it’s 20-100 times faster.
  • Log slow queries on your dev/beta environment and investigate them. This way you can catch queries which execution time is high, those that don’t use indexes, and also — slow administrative statements (like OPTIMIZE TABLE and ANALYZE TABLE)
  • Tune your database server parameters: for example, increase buffers size.
  • If you have lots of DELETEs in your application, or updates of dynamic format rows (if you have VARCHAR, BLOB or TEXT column, the row has dynamic format) of your MyISAM table to a longer total length (which may split the row), schedule running OPTIMIZE TABLE query every weekend by crond. Thus you make the defragmentation, which means more speed of queries. If you don’t use replication, add LOCAL keyword to make it faster.
  • Don’t use ORDER BY RAND() to fetch several random rows. Fetch 10-20 entries (last by time added or ID) and make array_random() on PHP side. There are also other solutions.
  • Consider avoiding using of HAVING clause — it’s rather slow.
  • In most cases, a DISTINCT clause can be considered as a special case of GROUP BY; so the optimizations applicable to GROUP BY queries can be also applied to queries with a DISTINCT clause. Also, if you use DISTINCT, try to use LIMIT (MySQL stops as soon as it finds row_count unique rows) and avoid ORDER BY (it requires a temporary table in many cases).
  • When I read “Building scalable web sites”, I found that it worth sometimes to de-normalise some tables (Flickr does this), i.e. duplicate some data in several tables to avoid JOINs which are expensive. You can support data integrity with foreign keys or triggers.
  • If you want to test a specific MySQL function or expression, use BENCHMARK function to do that.

Monday, March 18, 2013

Elements of HTML

Elements of HTML(Hyper Text Markup Language)


HTML markup tags are usually called HTML tags


  • HTML tags are keywords (tag names) surrounded by angle brackets like <html>
  • HTML tags normally come in pairs like <b> and </b>
  • The first tag in a pair is the start tag, the second tag is the end tag
  • The end tag is written like the start tag, with a forward slash before the tag name
  • Start and end tags are also called opening tags and closing tags



  1. A – How to display hyperlink?
  2. B – How to display text in BOLD style? 
  3.  Body – How and where to write content in the HTML file? 
  4.  Br – How to create a line break in html page? 
  5.  Code – How to display computer code in html page? 
  6.  Div – How to display division (section) in the html content?
  7.  Font – How to format text in color, size and font style in HTML? 
  8.  Form – How to display HTML form to submit data to other page?
  9.  Input – How to display Check box, FileUpload control, Image button, password textbox, radiobutton, reset button, submit button, multi-line textbox and button on the html page?
  10.  How to limit the number of characters allowed in the text box?
  11. IFrame – How to display a sub window in the html page? 
  12. H1 to H6- How to display headings in html page? 
  13.  Head – How & where to write title, meta, link and script tags in html page?
  14.  Hr – How to display horizontal line in html page? 
  15.  HTML – What is the use of html tag in html page?
  16.  Img – How to display image or picture in html page?
  17.  Label – how to display a label or associate a control with a label in html page? 
  18.  FieldSet – Legend – How to group or create a block of html controls in html page? 
  19.  OL/UL – LI – How to display ordered and un-ordered list in html page? 
  20.  Link - How to reference external css file in html page? 
  21.  Meta – How & why to write meta tags in html page? 
  22.  P – How to display a paragraph in html page? 
  23. Select - OptGroup – Option – How to display a dropdown list in html page? 
  24.  How to display a list box in html page?
  25.  How to display a list box and enable user to select multiple items from the listbox?
  26.  Pre – How to display pre-formatted content in html page? 
  27.  Script – How to write client side scripting language code in html page?
  28.  Span- How to write inline text with style in html page?
  29.  Style – How to specify CSS style information for an element or write CSS style class in the html page? 
  30.  Sub – How to write subscript text in html page? 
  31.  Sup- How to write superscript text in html page? 
  32.  Table, Tr, Th, Td – How to write data in tabular format in html page?
  33.  TextArea 
  34.  Title