rka05
(Raghav Agarwal 05)
June 16, 2014, 7:42am
1
Hi All,
I have read the OPCache is use to save pre-compiled script in php application.
But In Yii what is the process to use opcache. What configuration options are available, for the same?
How I come to know the effect of Opcache in my application.
I am using php 5.5.13 and Yii 1.1.14.
Further I am using yii 2.0 also.
But now my problem is with version 1.1.14
Any help will be appreciated.
Thanks
There’s nothing to configure in Yii itself. Simply enable opcache and you’re good to go.
rka05
(Raghav Agarwal 05)
June 16, 2014, 11:14am
3
Hi Sourcerer,
Thanks for your reply.
I have enabled opcache, which I checked from opcache_get_status().
I get [opcache_enabled] => 1.
Anything else I need to do.
In theory, no. In practice, you’re best advised to use a control panel (such as this one ) and see if you allocated enough space for the pcache to operate. I also wrote down some configuration settings here .
rka05
(Raghav Agarwal 05)
June 16, 2014, 11:25am
5
In theory, no. In practice, you’re best advised to use a control panel (such as this one ) and see if you allocated enough space for the pcache to operate. I also wrote down some configuration settings here .
I have already go through this link.
http://www.yiiframework.com/forum/index.php/topic/40353-php-55-apc-vs-zendoptimizer/page__p__240002#entry240002
and change opcache settings as per this configuration.
But still no success.
rka05
(Raghav Agarwal 05)
June 16, 2014, 12:03pm
7
It means.
public function actionTest()
{
$this->render('opcache');
}
and in opcache.php I just write
echo "hello";
Now I change text "hello" to "hello brother".
If opcache is working in the application, then on refresh the page the text should be "hello" not "hello brother", But I am getting "hello brother"
This is the issue, what I am facing.
I have enabled opcache and made all setting which you have told.
But not getting the expected result.
Sounds like the cache content is being purged before you can reload. The key value here is [font=“Courier New”]opcache.revalidate_freq[/font]. Check if it’s overwritten somewhere in your config. And make sure [font=“Courier New”]opcache.validate_timestamps[/font] is set to 0, as the cache will be refreshed if the timestamp of a cached file changes.
rka05
(Raghav Agarwal 05)
June 16, 2014, 1:11pm
9
Sounds like the cache content is being purged before you can reload. The key value here is [font=“Courier New”]opcache.revalidate_freq[/font]. Check if it’s overwritten somewhere in your config. And make sure [font=“Courier New”]opcache.validate_timestamps[/font] is set to 0, as the cache will be refreshed if the timestamp of a cached file changes.
Thanks.
validate_timestamps is set to 0, is life saver. Thanks a lot, Finally it works.
rka05
(Raghav Agarwal 05)
June 17, 2014, 6:33am
10
Hi Sourcerer,
This is working fine if I work with setting in opcache.ini.
But these settings are for all application on a server.
Is there any way through which I can set opcache enable or disable for different applications.
I was trying changing in .htaccess file and try disable opcache there using
php_flag opcache.enable Off
But it doesn’t work.
Any idea or any other changes I need to do.
rka05
(Raghav Agarwal 05)
June 17, 2014, 7:18am
11
I am able to do the same.
As I was previously changing in localhost/application/protected/.htaccess
At this location it was not working.
But then I create a new .htaccess at localhost/application/.htaccess
And put the above mentioned code in that file and it works.
rka05
(Raghav Agarwal 05)
June 17, 2014, 11:06am
12
Hi,
Is it possible in an application, that only few actions will work with opcache.
I don’t want to save all data save in cache. I want to save only few data as per requirement.
Any suggestions?
Is it possible in an application, that only few actions will work with opcache.
I don’t want to save all data save in cache. I want to save only few data as per requirement.
That is no good idea and I have serious doubts that’ll be possible at all. Those actions will likely pull in framework code into the opcache. You can try to explicitly blacklist a set of files.
As for your original problem: perhaps your Apache config doesn’t allow a [font=“Courier New”].htaccess[/font] were you first placed it. Check which [font=“Courier New”]AllowOverride[/font] directives match that directory.
rka05
(Raghav Agarwal 05)
June 17, 2014, 12:59pm
14
That is no good idea and I have serious doubts that’ll be possible at all. Those actions will likely pull in framework code into the opcache. You can try to explicitly blacklist a set of files.
As for your original problem: perhaps your Apache config doesn’t allow a [font=“Courier New”].htaccess[/font] were you first placed it. Check which [font=“Courier New”]AllowOverride[/font] directives match that directory.
Thanks for the reply.
Yeah you are right I had to change, in httpd.conf AllowOverride directive to All.
And regarding the blacklist option, I also go through this file details. But this doesn’t solve my problem.
Because I can write the path of scripts which are outside of my application.
So this is something which will not work in my case.
Any idea how can I achieve this.
It would be interesting to know why you would want this in the first place.
rka05
(Raghav Agarwal 05)
June 17, 2014, 1:27pm
16
Actually some times. There is an action which simply render a page. And in that page we have static HTML data.
Now if we using opcache, so this data also be cached and if I want to change this static data, to see the change effect I need to reset the cache.
Which I dont want to do. I dont want to cache this static data in my application.
I want to cache only dynamic data, which may sometimes cause error in my application.
So … you’ve got static data that isn’t that static? Is this in production or on your local development system?
rka05
(Raghav Agarwal 05)
June 18, 2014, 4:20am
18
This is for my local development system.
And how can I clear cached data? Currently I am doing this with server restart.
I tried function opcache_reset(). But it does not work.
rka05
(Raghav Agarwal 05)
June 18, 2014, 6:22am
19
This is for my local development system.
And how can I clear cached data? Currently I am doing this with server restart.
I tried function opcache_reset(). But it does not work.
opcache_reset() is working, I wrote it in a different function and then call that function from url.
So it helps me to clear the opcache.
But it clear all cache in the system. How can I clear cache for only specific data, not all data in cache.
You can invalidate specific files via [font=“Courier New”]opcache_invalidate()[/font] . But to be honest: You really shouldn’t enable opcache on your dev system.