Reputation: 13129
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?
Upvotes: 0
Views: 146
Reputation: 88657
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.
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.
Upvotes: 2
Reputation: 169018
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.
Upvotes: 4