php function_exists then ceases to exist - php

A plugin I'm using to move a wordpress install checks function_exists('mysqli_connect').
In the installer this check comes up as a failure, but from the command line php -r 'echo function_exists("mysqli_connect")?"pass":"fail"; echo "\n";' outputs pass.
What could be causing the function mysqli_connect to cease to exist?
I'm using php7.2, and I verified that is the running script with phpinfo().

The typical causes of this are 1 or more of the following:
Multiple PHP Installations. (CLI is 1, web-server is using another)
Apache/Nginx/PHP-FPM needs to be restarted (Typically a config file was updated but the related service(s) weren't restarted)
You have different php.ini files for CLI and your webserver (which means you need to turn on the extension in your web-server's php.ini)

Related

PHP CLI on Win10 no longer loading local ini file after upgrade to 7.4

I used to run PHP 5.6 on Win 10 in CLI mode. I had different php.ini files in different directories and PHP would always pick up the one in the current directory if one was there.
Now, after upgrading to PHP 7.4, PHP always loads the php.ini from where php.exe is installed.
I know that I can specify a different php.ini with the -c command line directive, but that's not convenient. Is there a way to restore the 5.6 behavior?
Additional info:
I'm seeing the same behavior change on the LINUX web server: local php.ini files that used to be loaded now get ignored. I was able to mostly solve it there by renaming them to .user.ini

Laravel artisan command ignores php.ini setting for Memcached

I'm trying to enable memcached on my file server. I have added the line 'memcached.use_sasl = 1' in my php.ini file, and restarted apache2.
A phpinfo(); command shows that memcached.usesasl is set to 1.
However, whenever I run a php artisan command I get the following error message:
Memcached::setSaslAuthData(): SASL support (memcached.use_sasl) isn't enabled in php.ini
I made sure to run the phpinfo() from within my laravel projects public/index.php to make sure that I was looking at the configuration that Laravel is using (just in case it was using a different php somehow?) and it shows memcached.use_sasl is set to 1.
Apache-embedded PHP and command-line PHP often use separate ini files. Check for php-cli.ini in the same dir as php.ini. You can also run php --ini and it will show what files it uses.

PHP Version on the Command Line with MAMP for Windows

I run MAMP on my Mac at home, but on my work machine (Win7) I just started using MAMP for Windows so that I'm running the same (relatively speaking) software between the two machines. I was running some commands from the command line yesterday and noticed that the script was throwing errors because the mbstring extension wasn't loaded. I did some digging and am left scratching my head now...
In the browser, everything works fine. When I check the phpinfo, it's loading the configuration file just fine and mbstring is enabled. When I switch to the command line though, mbstring isn't in the list of modules (php -m). Also, when I do a php --ini, it tells me that no configuration file was loaded. I've added the correct PHP version to my PATH and running php -v gives me the version I expect, so I'm not really sure why PHP on the command line is acting differently from PHP in the browser.
Has anyone run into this before? How do I make PHP on the command line load the same configuration file that the browser is using?
Command line php (CLI) is a different executable to CGI PHP. It also uses typically a different php.ini file. You can however specify the location of the php.ini you would like to load when launching php cli:
php -c <path to your php.ini>
Have a look here.
This example assumes you use C:\MAMP\ as installation directory.
As you need configuration as used in Windows MAMP you will need to supply it as argument to php.
Open command prompt.
To execute test.php with script located in C:\MAMP\htdocs\ by using PHP5.6.0 from MAMP:
C:\MAMP\bin\php\php5.6.0\php.exe -c "C:\MAMP\conf\php5.6.0\php.ini" "C:\MAMP\htdocs\test.php"
As you can notice last argument is the script to be executed ("C:\MAMP\htdocs\test.php").
To execute phpinfo from command line:
C:\MAMP\bin\php\php5.6.0\php.exe -c "C:\MAMP\conf\php5.6.0\php.ini" -r phpinfo();
There should be line from phpinfo output which acknowledges that you're using configuration from C:\MAMP\conf\php5.6.0\php.ini.
Loaded Configuration File => C:\MAMP\conf\php5.6.0\php.ini

ob_start() failed to create buffer in laravel three

I am using Laravel 3 for a project, and I've made a little cronjob script, and when I moved to the new server it keeps saying:
Warning: ob_start(): function 'mb_output_handler' not found or invalid function name
and
Notice: ob_start(): failed to create buffer
Any idea how to fix this?
The new server is Ubuntu? Are your development server and the "new server" the same OS? Same PHP versions?
It's possible the two servers are completely different!
Can you show your cronjob? (Does it attempt to use a specific php binary via a #!/usr/bin/env php call ?
One possibility for Ubuntu:
PHP run in CLI can be different from being run in Apache, and especially is likely different if you're using php5-fpm with Nginx.
They each can have their own php.ini and different extensions loaded.
As you said, you're using Ubuntu Server. If you're using php 5.5, you may note a few things in /etc/php5:
/etc/php5/mods-available # All mods available / installed
/etc/php5/cli/php.ini # php.ini for CLI-called php5
/etc/php5/cli/conf.d # Directory of symlinks to extensions in mods-available!
/etc/php5/apache2/php.ini # php.ini for Apache-run php5
/etc/php5/apache2/conf.d # Symlinks to mods-available extensions
So, php in CLI vs Apache2 vs PHP-FPM can all have different extensions loaded and separated php.ini's installed.
Perhaps the cli-based one (likely what the cronjob is using) may be a different version of PHP (!) or loading a different .ini file and/or set of extensions.

Fatal error: Class 'ZMQContext' not found ( but it is installed and works on the terminal )

I want to try the ZeroMQ, and I write two php file, service.php and client.php.
I use the linux terminal to run service php /web/test/service.php,it's ok, terminal print a "waiting for client connecting...".
but, I request my client.php through chrome explorer,error happened, I check my error.log,there is message "php fatal error: class 'ZMQContext' not found........"
and I use command php -m to check my php extension, zmq is already in that list.
The problem is that the ZMQ module is loaded in the PHP CLI (Command Line Interface) but it's not loaded into Apache. Therefore, service.php runs smoothly from the Command Line but client.php can't use ZMQContext because Apache does not load ZMQ.
There are two different .ini-files. These probably are (but can be different, depending on your distro):
/etc/php5/apache2/php.ini for Apache
/etc/php5/cli/php.ini for CLI
However, all .ini files from the /etc/php5/conf.d/ directory are loaded into both Apache and the CLI.
See also: PHP - An external Class/library is accessible from apache but not from phpunit (the exact opposite of your problem)
Check which php.ini files are loaded
Checking (with phpinfo) which php.ini files are loaded when requested via nginx (which probably means via php-fpm) - will almost certainly reveal that it loads different ini files than the cli. Assuming php-fpm usage, the following ini files are probably loaded:
/etc/php5/fpm/php.ini
/etc/php5/fpm/conf.d/*
and no zmq.ini file listed.
Loading zmq for php-fpm
Follow the instructions for installing zmq on php, and create an ini file for zeromq (or copy the one from /etc/php5/cli/conf.d/ since evidently it's loaded for cli usage):
# /etc/php5/conf.d/zeromq.ini
extension=zmq.so
Then restart php-fpm
sudo /etc/init.d/php5-fpm restart
And zeromq should be available for use.
A really easy way to solve this issue is to enable ZMQ globally (cli + Apache) with phpenmod
For example with php5
php5enmod zmq
service apache2 restart

Categories