0

I am converting php to run from cgi mode to module mode for performance reasons.

In CGI mode the php code was executing every time. I had the feeling that with this conversion php code will run in memory just like Java. That means if user class was instantiated when user first logged in, it will remain as a class in memory. But it doesnt seem so. All the code needs to be executed every time.

Is there a way to run PHP like java?

Thanks

1
  • What exactly are you trying to do? Commented Jan 11, 2011 at 0:33

2 Answers 2

2

No, module version of PHP works the same as CGI version in that regard, so you cannot keep class "in memory" between requests.

So, you still need to store/serialize your data between requests, that means use sessions, because every request will be processed by a "new" script.

You want to use "Application Server", but PHP doesn't work that way (AFAIK), and PHP Apache module is not an application server.

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

Comments

0

I am not totally clear on your question, but if you are asking about caching the bytecode of the php file to reduce load times, I would look into using APC (http://php.net/manual/en/book.apc.php).

It will cache the bytecode of your php and significantly reduce the time it takes to load an unchanged class.

3 Comments

i looked into APC and it has helped a lot. The code is 50% faster.
I had another question on APC. Not sure if i should create a new thread. I want to ideally have 2 caches - one static for common includes and 2nd one dynamically built/flushed based on requests. I only see the cache can be completely dynamic (old pages get flushed when new ones are added. apc.user_ttl ne 0) or static (when cache gets full first time, no more pages can be added apc.user_ttl=0). Also Ideally i like to preload pages on start of httpd server (via php module) but it doesnt look like this option is available (tried apc.preload_path but doesnt seem to work). Thanks
Might be a different question - especially since I am far from a APC expert and you might get one if you tag it with APC. How many php files are you talking about? I would think that unless you are talking about tens of thousands, giving APC a moderate amount of memory would more then do the job.

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.