0

Question 1: How many characters MAXIMUM can be stored in a regular php variable? example: $x="blablablablabla....";

Question 2: The reason why I am asking #1 is that I was wondering if it was better for performance to perform a single SQL INSERT of 10 000 lines at the end of my loop or to perform 10 000 INSERTS of 1 line on each loop? Does it make any difference or it's the same?

2 Answers 2

4

Question 1 is irrelevant, because there is going to be a performance issue long before you reach the maximum string allocation.

Ultimately, the answer to question 2 will probably lie between a one-row insert and a 10,000-row insert. For example, perhaps doing 100 inserts of 100 rows will be faster. Benchmark and test to determine the optimal number of rows per query.

Sign up to request clarification or add additional context in comments.

3 Comments

So there isn't one accepted general answer. I'll try doing what you say about 100 inserts of 100 rows, but i still don't understand why.
^^ what he said, LOL. I wrote mine before I was notified of this answer, honest...
@Adam: Exactly. Which method is faster is going to depend on several factors, such as memory and CPU speed (for concatenation), DB connection latency, and possibly even disk speed. And, of course, the optimal number of rows per query is going to change as these factors change... so if you develop and deploy on two different machines, they will likely perform differently.
2
  1. Limited by the memory_limit PHP INI directive. If your using a recent PHP build (>5.2.0), this is default 128MB, so probably way more than you would ever get near. You also would encounter other problems long before you reached this limit. These problems are OS specific and totally unknown until you actually try and do it.

  2. This is debatable. It depends on a thousand factors - how your MySQL server is configured, where it is hosted (if it's on the same box as your PHP instance that answer would differ from if it was on a dedicated box), to some extent the speed of the network connection, the amount of memory MySQL has available to it, etc etc. You would probably have to benchmark each individual hosting environment if you wanted a definitive answer. In reality, the answer is probably, more than 1, but less than 10000.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.