0

I googled and didnt find any explanation. By "position of code" I mean, for example you have to fetch users very frequently and the portion of code that does that comes after 2000 lines in script file

.
. //2000 lines of code above
.
.
//code portion for user fetch
.
.
.
.

Will it affect the speed or performance in any way?

My code is like

if(isset($_POST['id'])) 
{ //code }

if(isset($_POST['name'])) 
{ //code }

.
.
.
Ace
  • 841
  • 9
  • 23
  • 2
    Depends on what is being run in between – Flosculus Dec 16 '13 at 17:20
  • well..when loaded all the code is processed at once...so i dont't think that it matters whether you place the fetching at the beginning or at the end... – SpiderLinked Dec 16 '13 at 17:21
  • A lot more information would be needed to answer, but the best advice is to setup a benchmark for yourself. If you are fetching in loops, or in batches, all these things may have an effect, but with no code we can't help. – Michael Berkowski Dec 16 '13 at 17:21
  • @MichaelBerkowski the code is like `if(isset($_POST['id'])) { //code }` A number of snippets like this are in my file – Ace Dec 16 '13 at 17:22

2 Answers2

1

For PHP, the answer is probably no. Or rather, you won't see any difference.

Because the whole source file is parsed beforehand and "compiled" to internal representation. Once parsed, there will be no access made to the source file, and therefore no disk slowness involved.

If we dig a little deeper, we can probably assume that functions that are too big require more processor time to be executed, as memory, paging and caching has its surprises. Alas, unless knowing the internals of PHP and your hardware, probably no one can give you a precise answer to this.

You can probably safely assume that it doesn't make a difference. But please, please, do not use this as an argument to write lengthy code...

aspyct
  • 3,625
  • 7
  • 36
  • 61
0

If you are talking about execution order, then the fetch is occurring last, so naturally that statement needs to wait.

However for page execution it doesn't really make any difference. Its like waiting for 2 people to finish a race, one is fit, the other is not. It doesn't matter who breaks the line first, the unfit racer will determine the overall duration of the sprint.

Flosculus
  • 6,880
  • 3
  • 18
  • 42