Manipulate directly $ _GET and $ _POST

1

I have an application that will work with a large amount of data to be manipulated and stored in a database, so it is advisable to store the values present in variables $_GET and $_POST in intermediate variables (which would lead to duplication of memory spent) or directly change $_GET and $_POST ?

    
asked by anonymous 23.01.2015 / 17:20

1 answer

4

There's nothing to stop you from manipulating this variable. I do not know anything that indicates that it will create any problem. There is nothing in the documentation that tells you to avoid it. But some considerations must be observed.

  • PHP is not the best language for working with large volumes of data at once. Much less is the language to think about when one expects great optimization of resource use. If you really need this, choose the right tool.
  • With $_GET you can not manipulate millions of data. There will never be even thousands if the protocol is respected.
  • If you are going to receive millions of fields in one request you are doing something very wrong, there are so many other problems that can occur, so much to worry that this problem comes to be almost irrelevant.
  • PHP does not keep data in memory that is no longer referenced. At least it says it does not hold. So I do not know if this duplication would have you waiting.
  • You need to see if you really need to duplicate. I understand you want to write this array . But almost always what people want is to just read the content of it and use it somewhere. There is no problem in this. Anything. I notice that some programmers think it is necessary to play a field coming from $_POST in a local variable and then use the variable. This really is waste probably caused by people's insistence on cake recipe instead of learning to develop software.
  • Otherwise, it's a completely unnecessary optimization.
  • If you still insist on this, take a stress test and come to some conclusion for your actual case. No one can give you better information than this.

The exception would be if you are using threads , which I doubt will be the case. By the nature of PHP programs they rarely benefit a program. Again, if someone thinks they need thread to get better performance, they will probably opt for another language.

    
23.01.2015 / 17:47