I must search over huge data from db through php code. I'd rather not give many db hits. And so i selected all data from db to become looked and attempted to keep it in array to complete further explore array this is not on db, but problem would be that the data surpasses the limit of array. How to proceed?

Avoid that.

Databases are made particularly to deal with considerable amounts of information. Arrays aren't.

Your best choice is always to correctly index your db, after which write your enhanced query which get the information you require from the database. You should use PHP to create the query. You will get just about anything from the db via a good query, no requirement for PHP array processing.

Were you to give a particular example, we can help you construct that SQL query.

Databases exist to filter the information for you personally. Make use of the most accurate query you are able to, and just filter in code whether it's way too hard (or impossible) to complete in SQL.

A complete table selection could be a lot more costly (specifically for I/O around the db server, also it can have dire effects around the server's cache) than the usual properly indexed select using the appropriate where clause(s).

There's communication overhead involved when acquiring records from the database to PHP, so it's not only smart to reduce the amount of calls from PHP towards the database, but it's also ideal to reduce the amount of elements came back through the database and processed inside your PHP code. You need to structure your query (with respect to the kind of database) to come back only the records you'll need or as couple of records as you possibly can for whatever you must do. You will find lots of databases that support fairly complex procedures directly inside the database query, and often the database is going to do it way faster than PHP.

Two easy steps:

  1. Increase the quantity of memory php may use through the memory_limit setting

  2. Install more RAM

Seriously, you will be best optimizing your database in ways that you could rapidly pull the information you have to focus on.

If you're really encountering problems, then operate a query analyzer to determine what queries take a lot of time. Fix them. Do this again.