views:

40

answers:

1

When I set ini_set('memory_limit', '100M'); in an included script, does this apply to the complete request, in which this script is included?

+1  A: 

Update re acmatos' comment: Yes, if you call set_memory_limit in a child include, it will apply to the whole script. An include is not a separate process of any kind, but simply another place for the PHP interpreter to look for code. To the interpreter, there is one script, no matter how many files you include.

The only exception is when you include a file using a http:// URL. That is treated like a remote request even though it points on localhost. For that, a new request is started to parse that file, a new PHP process is started, which has its own memory limit. This practice is highly unusual though.

Old answer:

I'm not sure what you mean by "complete request" in this context, but the answer is probably no. The memory limit applies to the PHP script only and memory allocated/used by it. It does not apply to any external binaries called using exec() for example.

Pekka
I think he is including a .php script inside another and the child one has the `ini_set`. So the question is if the included `ini_set` will also apply to the parent script. If that's the case think "yes" but I'm not sure.
acmatos
@acmatos I see, thanks for clarifying. Updating my answer.
Pekka
Thank you, the updated answer is the one I hoped for!
Labuschin
@Labuschin you're welcome. Note however that changing the memory limit inside the script is usually disabled on shared hosting, so it may not have any effect at all.
Pekka
@Pekka Do you have source on the "http://"-spawn-new-process claim?
Artefacto
@Artefacto no source necessary IMO: Requesting a resource like `http://domain.com/script.php` will always start a separate http request, which will spawn a separate PHP process. There's no way for it to behave differently, is there? Things would be different for *clear text PHP source code* emitted by such an include and *interpreted* inside the including script instance. That would be executed in the script's context. This would be doubly unusual though, and a highly dangerous practice so I'm not really taking it into consideration.
Pekka
Oh, OK, I thought you referring to the second case.
Artefacto