PHP 5.5 OPCache not working on apache - php

I'm in charge of the opcode cache exchange here in my company, we're moving from eaccelerator to the Zend OPCache shipped with PHP 5.5.
When I access PHP in CLI, it seems like the OPCache is working fine:
PHP 5.5.5 (cli) (built: Oct 15 2013 10:29:13)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
But when I access my website via Apache, the benchmarks show no improvements compared to the same pages using no opcode cache. Also, get_loaded_extensions(true) returns an empty array.
Can anyone answer me why on earth it isn't working?
I'm using windows 7, Apache 2.4.6 from Apache Lounge, PHP 5.5.5 from windows.php.net.
EDIT:
As requested, my OPCache configuration:
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
;opcache.max_wasted_percentage=5
;opcache.use_cwd=1
;opcache.validate_timestamps=1
opcache.revalidate_freq=60
;opcache.revalidate_path=0
;opcache.save_comments=1
;opcache.load_comments=1
opcache.fast_shutdown=1
;opcache.enable_file_override=0
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
;opcache.blacklist_filename=
;opcache.max_file_size=0
;opcache.consistency_checks=0
;opcache.force_restart_timeout=180
;opcache.error_log=
;opcache.log_verbosity_level=1
;opcache.preferred_memory_model=
;opcache.protect_memory=0

Found the answer!
zend_extension extensions must set the complete path, not a relative one.
In this case, zend_extension="C:\Apache24\php\ext\php_opcache.dll" solved my problems.

WINDOWS PHP 7 SOLUTION
By default there are opcache settings in php.ini files like opcache.eneable but enabling opcache does not take effect unless you add:
zend_extension=php_opcache.dll
to your config file. Remember it is zend_extension and not regular exstension !

Make sure that you have "opcache" in your phpinfo(); report. By default:
A DLL for this PECL extension is currently unavailable. See also the building on Windows section.
Can you confirm that the extension is loaded?

Related

How to find the right php.ini that your Apache is using?

I'm a bit confuse on my PHP versions on my local Mac OS X.
When I ran
⚡️ ~ which php
/usr/local/php5/bin/php
⚡️ ~ php --version
PHP 7.3.8 (cli) (built: Aug 11 2019 20:50:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.8, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
⚡️ ~
so this means my CLI version is 5 or 7.3 ?? 😵 !
When I run
php -r "echo ini_get('memory_limit').PHP_EOL;"
I got
256M
the result of that matched with my Apache PHP
See picture below
phpinfo()
I really need to update the meory_limit.
How do I find php.ini of my Apache use?
Updated
I tried to modify /usr/local/php5/lib/php.ini
and set memory_limit = 40096M ~40GB
I never see that settings take place.
Maybe you should just rename /usr/local/php5 to /usr/local/php and the confusion is gone ;)
On your phpinfo() page is a section called "Loaded Configuration File" and "Additional .ini files parsed". These are the files to edit.
I am not sure if there is an upper limit for memory_limit. Maybe just try to set it to -1 to disable it.
Some php installations use different .ini files for running in a cli and running in a browser, to check what .ini files are used on command line use php --ini.

Debug session was finished without being paused

In my Laravel project using PhpStorm (2018.1) I am not able to debug my session using xdebug (2.9.5). Any breakpoint gets ignored and session ends without being paused. If I set Break at first line in PHP scripts then session stops at index.php file. I am using Ubuntu 20.04.
PHP 7.4.5 (cli) (built: Apr 23 2020 08:10:29) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.9.5, Copyright (c) 2002-2020, by Derick Rethans
This are my settings for xdebug in php.ini
[xdebug]
zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9001
xdebug.remote_log="/tmp/xdebug.log"
I have some PhpStorm settings:
What am I missing here?
I also have Xdebug helper extension in my Chromium but it seems to have the same effect with it enabled as well as disabled.
In my Laravel project using PhpStorm (2018.1) I am not able to debug my session using xdebug (2.9.5).
It just triggered:
PhpStorm 2018.1
Xdebug 2.9.5
You have to upgrade PhpStorm. You need PhpStorm 2018.3 or newer in order to be able to work with Xdebug 2.7 or newer.
The problem is in changed XML namespace in Xdebug protocol, as of Xdebug 2.7 (https instead of http). It's fixed/supported since PhpStorm 2018.3 (see WI-43622).
With your current IDE version you may work with Xdebug 2.6.x max (which does not support PHP 7.4).

Deactivating and uninstalling Zend Opcode caching

I have installed the Zend OpCache on my linuxbox. I used the following command to install the extension:
sudo pecl install zendopcache-7.0.2
Now without modifying my php.ini file, the extension is enabled. This claim is based on the output I am getting for the php -v command. Following is the output I am getting for php -v command:
PHP 5.5.14-1+deb.sury.org~precise+1 (cli) (built: Jun 27 2014
14:11:34) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0,
Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
It also seems as Zend Opcode caching is enabled by default. Can someone help me deactivating Zend Opcode caching as I need to evaluate some other Opcode cachings? In my php.ini file, I dont see any Zend Opcode caching option.
In case if I want to uninstall the Zend Opcode caching completely from my vm, how can I achieve this?
Just disable the opcache module. On a linux system with php 7 run
sudo phpdismod opcache
on older php 5 systems
sudo php5dismod opcache
Zend OPcache is integrated since 5.5 if i remember correctly. So no need to install from pecl.
Create a new ini file or use the one available on your system to enable / disable opcache
opcache.enable 0
opcache.enable_cli 0
Uninstall Opcache by runnning the following command:
sudo pecl uninstall zendopcache-7.0.2

Multiple PHP versions using phpenv, php-build and php-version

I'm on Arch Linux, trying to configure multiple PHP versions for testing my scripts.
I'm basing myself on these three tools:
https://github.com/phpenv/phpenv
https://github.com/CHH/php-build/
http://wilmoore.com/php-version/
First I installed Apache and PHP (and their integration package) with pacman:
# pacman -S php apache php-apache
Next, I followed the instructions for installing the tools on the links, everything is working fine.
I manage to install two versions with phpenv-install from php-build tool. I got something like this:
-- ~
|---.phpenv
|---lib
|---versions
|---5.5.1
|---5.4.17
|--- (some more folders)
On CLI environment everything is working fine, I can easily switch between the two versions with php-version:
$ php-version 5.5.1
$ php --version
PHP 5.5.1 (cli) (built: Aug 5 2013 22:54:47)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
$ php-version 5.4.17
$ php --version
PHP 5.4.17 (cli) (built: Aug 5 2013 23:19:44)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
Now the problem: integrate this with apache.
As I said in the beginning of this post, I also had to install PHP from Arch repositories, which coincidentally is on version 5.4.17. This installation is working fine with Apache.
On php-env readme there are these instructions:
phpenv support dynamic switching for Apache apxs libraries and install
will build and install a libphp5.so shared library for Apache under
the versions libexec folder.
By calling phpenv global to show or change the global PHP version a
link is created under ~/.phpenv/lib/libphp5.so for the appropriate
release build. This link can be used for Apache's LoadModule
php5_module directive and requires Apache to restart when changed.
The problem is that there is no file or symlink named libphp5.so in lib directory neither in the whole .phpenv folder, because
$ find ~/.phpenv -name libphp5.so
returns nothing.
Maybe because english is not my first language, I'm having some problem to intepret the second paragraph of the quote above.
There is a package in the AUR for phpenv
https://aur.archlinux.org/packages/phpenv/
As well as packages for many different versions of PHP
https://aur.archlinux.org/packages/?O=0&C=0&SeB=nd&K=phpenv&outdated=&SB=n&SO=a&PP=50&do_Search=Go
First install phpenv:
yaourt phpenv
Then install the php versions you need, for example:
yaourt php53_29_env
Note: even with this though, you will likely have a problem. Checking the package build, it looks like it is missing the patch to disable PHP automatically being compiled with thread safe features when apache is running a thread safe mpm. Not quite sure since on my systems, I want PHP to enable thread safe code so it will work for me.

(Windows, Mac) How to load both XDebug & ionCube Loader simultaneously?

I am trying to load XDebug & ionCube loader simultaneously, when I type zend_extension_ts="path/to/ioncube_loader_win_5.2.dll" or zend_extension_ts="path/to/php_xdebug.dll" alone in php.ini they work. But I cant get them working simultaneously. Is there any way I can load them both ?
I was thinking if I can load them only for particular directory/project, I don't know if it is possible.
Xdebug is not compatible with ioncube: http://xdebug.org/docs/install#compat You can not have them both installed in the same server environment, so you'll have to set-up two server instances (or use lighttpd/nginx with two fast-cgi configurations) as I have described here: http://derickrethans.nl/multiple-php-versions.html
I have installed ionCube successfully on the top of Zend debugger without running into any issues,
To Install ionCube, I have downloaded the zip file for my OS from here
then I ran the localhost/ioncube/loader-wizard.php, it will tell you step by step what to do, for me because I have windows and wamp server I had to insert the ioncube folder in
C:\wamp\bin\apache\apache2.4.9\bin\
here is the php version and explanation:
PHP 5.5.12 (cli) (built: Apr 30 2014 11:20:58)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
I saw in other stackoverflow post mentioned by Arte Arefjev that the zend_extention of ioncube should be the first one to load so I did this:
zend_extension = "C:/wamp/bin/apache/apache2.4.9/bin/ioncube/ioncube_loader_win_5.5.dll"
zend_extension = "c:/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.2.5-5.5-vc11-x86_64.dll"
all my debugger and at the same time my ioncube is working fabulous!
Hope it will help someone in the future.
For me it seems to work with php 5.3.10 as it says
with the ionCube PHP Loader v4.2.1, Copyright (c) 2002-2012, by ionCube Ltd., and
with Xdebug v2.2.0rc1, Copyright (c) 2002-2012, by Derick Rethans
but i havent tested debugging with files containing ioncube encoded content yet.

Categories