ob_start() failed to create buffer in laravel three - php

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.

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

Module pcntl already loaded in Unknown on line 0 - Apache x Cli

I'm getting this PHP Warning:
Module 'pcntl' already loaded in Unknown on line 0
But it is only enabled for Apache. Enabled it on /etc/php/7.2/apache2/conf.d/20-pcntl.ini:
extension=pcntl.so
I don't have it enabled on CLI. Checked with:
I don't have a /etc/php/7.2/cli/conf.d/20-pcntl.ini file
Grep command grep -R extension=pcntl.so /etc/php/7.2 only returns the file on apache2 folder
If I disable this extension on Apache's .ini, it won't load on Apache but loads on Cli.
If I enable this extension on Apache's .ini, I get the module already loaded warning.
I'm need to enable PCNTL on Apache to use Spatie\Async library.
It's a Ubuntu 14 server.
Sometimes extensions are compiled into PHP rather than loaded as separate modules. Before fiddling with the PHP.ini files, you should probably run a quick PHP script to see what modules are loaded:
<?php
var_dump(get_loaded_extensions());
You should also beware of PHP directives like disable_functions which may be disabling the pcntl functions. On my Ubuntu workstation, the pcntl functions are disabled with this directive:
/etc/php5/apache2/php.ini:disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority
I suggest you try a broader grep search to see if pcntl gets mentioned in other places:
grep -ir pcntl.so /etc/php/7.2
I don't have a /etc/php/7.2/cli/conf.d/20-pcntl.ini file
That seems a bit weird to me. You might try searching for more php.ini files there:
sudo find /etc -name "php.ini"
You should also check to make sure that you aren't running a different PHP from the command line than you are with apache. Under certain circumstances (which regrettably happen more often that you might think) your CLI PHP is different than your Apache PHP. This article discusses that issue in more detail.
If I disable this extension on Apache's .ini, it won't load on Apache but loads on Cli.
That actually sounds reasonable to me. If I had to guess, I would say that the wise Ubuntu/Debian package manager folks decided it would be unwise to allow pcntl_x functions to run in an apache environment, especially given this stark and ancient warning. I don't recall if that warning is outdated now or not. I would refer you to this other thread where I asked some related questions and was told I should use PHP-FPM with apache in event mode.
All that said, I have had some tremendous success writing "multithreaded" applications in PHP (technically not multithreaded but rather multiprocessing) using pcntl_fork and posix_setsid and the like.
To summarize, I'm guessing that PCNTL is already loaded both on apache and cli and the wise Ubuntu devs probably disabled the pcntl functions in the php.ini.
I know this is long after the original post, but I faced a similar problem. I'm working on a AWS Linux AMI and pnctl seems to be pre-installed into php-cli (not loaded via php.ini)
The problem is Spatie async checks your PHP Runtime (PHP-FPM) to see if the pnctl and posix modules are loaded, which by default aren't even though they are available in php-cli which it actually uses when you create Spatie Async Pools.
My solution was to actually modify the php-fpm service to run with extension=pnctl.so
systemctl edit php-fpm
It will create an override file in /etc/systemd/system/
Modify the file by changing
ExecStart=/usr/sbin/php-fpm --nodaemonize to ExecStart=/usr/sbin/php-fpm -d extension=pctnl.so--nodaemonize and save that
Then restart your nginx and php-fpm services and pnctl should be active for PHP-FPM

How to install PHP 7 extension "memcache" on Windows

I'm having huge problems installing memcached extension for php.
Currently using:
OS: Windows 10 x64
PHP: 7.0.1 via XAMPP
Apache: 2.4.18 (Win32)
I have successfully installed memcached in C:/memcached the service is running.
But the problem starts when trying to add the memcache php extension. I've tried numerous versions of php_memcache.dll and non seem to be working. I did include the extension in php.ini extension=php_memcache.dll
When i run php -m memcache is not listed and at the top i recieve the error:
PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_memcache.dll' - The specified module could not be found.
And when I try running a test.php for memcache initialization i recive the Class not found exception
This is a huge problem, because I need it for running selenium tests.
The memcached service doesn't actually install the PHP memcached extension for you. It only installs the memcached server used to store your cache.
You'll need to download the Windows DLL from the PECL repository first (click on the blue Windows DLL link). Then you must add the extension=php_memcache.dll line to the correct php.ini file for your SAPI. Also, note the extension DLL file needs to be placed in the correct path for your XAMPP installation.
For Apache, simply create a script in your document root with the line <?php phpinfo(); and try loading that in your web browser. You should see a line at the top labeled Loaded configuration (php.ini) which gives you the full path to your loaded php.ini file. On Windows the path may actually appear different than what is stated in phpinfo() if you installed PHP through something like XAMPP. So you may need to rely on XAMPP to locate the correct php.ini file.
For the CLI SAPI, you can use php.exe --ini to do the same. Again, you may need to rely on the XAMPP package if it has modified your configuration path (since this is a compile time directive).
After making your changes to php.ini you will need to restart PHP for the changes to take effect.
Since you're using PHP 7 on Windows it's probably also important to note that the compiled DLL from PECL may not actually work under apache for Windows, because you're more than likely using a theaded SAPI. So make sure you are downloading the correct version. As far as I can tell that version is only compiled to work with up to PHP 5.6. The github alternative, for PHP 7, available at https://github.com/nono303/PHP7-memcahe-dll as mentioned in the comments is tested under non-thread safe. So you may only be able to get this working for your CLI scripts on Windows.

Disable error log file creation by php [duplicate]

I run a PHP script and get this error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/ixed.5.2.lin' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/ixed.5.2.lin: cannot open shared object file: No such file or directory in Unknown on line 0
What does that mean?
It means there is an extension=... or zend_extension=... line in one of your php configuration files (php.ini, or another close to it) that is trying to load that extension : ixed.5.2.lin
Unfortunately that file or path doesn't exist or the permissions are incorrect.
Try to search in the .ini files that are loaded by PHP (phpinfo() can indicate which ones are) - one of them should try to load that extension.
Either correct the path to the file or comment out the corresponding line.
If you're on Linux, you can find all loaded configuration files by typing this in shell:
php -r "print phpinfo();" | grep ".ini"
UPDATE:
As mentioned in comments, this can be even more accurate:
php -i | grep ini
phpStom with XAMPP
TL;DR Except from verifying that the files exist, you might need to add the drive letter to some records in your php.ini file
I suddenly started having a problem using phpStorm 7 for debugging php with xampp and xdebug. When trying to set intellij interperter to be xampps php I got a lot of the warnings like the one in the question, for example:
Unable to load dynamic library '/xampp/php/ext/php_bz2.dll'
For some reason I had to add my drive letter to the records of extension_dir and browscap in the php.ini file:
extension_dir = "\xampp\php\ext"
browscap = "\xampp\php\extras\browscap.ini"
to
extension_dir = "e:\xampp\php\ext"
browscap = "e:\xampp\php\extras\browscap.ini"
If you just want to make the error disappear, and you don't need the extension, then by all means comment the line out in php.ini. But if you actually want to fix the problem here is some additional info.
There are various causes for this based on the exact module, but there are also some general guidelines.
Open phpinfo() and look for extension_dir under the Core section. This is where your modules should be located.
For instance, /usr/lib/php/modules for Unix/Linux.
If the file does in fact exist, make sure permissions are adequate.
If the file does not exist, use the resources below to install it.
Installation on *nix (PEAR)
Installation of extensions on Windows
Loading .dll in Linux
I've encountered this warning message while I was trying to install a php-extension via the php.ini file;
until I figured out that you cannot load .dll extensions in Linux,
but you have to comment the extensions that you want to import ;extension= ... .dll and install it correctly via sudo apt-get install php-...
note: ... is the extension name you want to enable.
php -r "echo php_ini_loaded_file();"
Will show in CLI current ini loaded file, search there for Your extension, path to it is incorrect.
In my case, this message started to appear when I updated the php version to 7.4.
To solve it I had to look for the php.ini files found inside the php version folder (/etc/php/7.4/apache2/ && /etc/php/7.4/cli/) checking the lines where the extensions I could see that the extensions gd2 and intl were uncommented.
Note that you can also get this error if your PHP library doesn't have the "other" directory opening permission. In my particular case, I noticed this when using php -l to syntax check a script in my text editor. This meant that since my account was called "volomike", that account didn't have permission to run the libraries that the php command relied upon.
For instance, on Ubuntu 14.04, I had PHP5 installed automatically into the path /usr/lib/php5/20121212+lfs. However, because I was working in C++ in building some shared objects, I messed around with the directory permissions and screwed things up such that non-root accounts did not have the directory execute (directory open) permissions to view /usr/lib/php5/20121212+lfs. So, I typed the following command to rectify that problem:
sudo chmod o+x /usr/lib/php5/20121212+lfs.
Now when I do php -l example.php as a non-root user, it never gives me this "Unabled to load dynamic library" problem anymore.
I had the same problem on XAMPP for Windows when I try to install composer.
I did php -v and php throwing error :
Unable to load dynamic library '/xampp/php/ext/php_bz2.dll'
It took me a while until I realized that I need to setup my XAMPP. So I run setup_xampp.bat and php return to works like a charm.
I had this error on a number of modules when I had been running different versions of PHP side by side on my server. To sort this out, I needed to install the packages it couldn't find for that specific PHP version. So, for example, if I saw:-
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/xml.so'
I would install the library for the PHP version specifically:-
sudo apt-get install php7.1-xml
And then restart Apache. Fixed it for me. You can check your version like this:-
php -v
I had the same problem on XAMPP for Windows10 when I try to install composer.
Unable to load dynamic library '/xampp/php/ext/php_bz2.dll'
Then follow this steps
just open your current_xampp_containing_drive:\xampp(default_xampp_folder)\php\php.ini in texteditor (like notepad++)
now just find - is the current_xampp_containing_drive:\xampp exist?
if not then find the "extension_dir" and get the drive name(c,d or your desired drive) like.
extension_dir="F:\xampp731\php\ext" (here finded_drive_name_from_the_file is F)
again replace with finded_drive_name_from_the_file:\xampp with current_xampp_containing_drive:\xampp and save.
now again start the composer installation progress, i think your problem will be solved.
What I did was;
1 - I first find out what version of PHP I am using thru the function phpinfo()
<?php
phpinfo();
?>
2 - From there you will find the location of your configuration(php.ini) file
3 - Open that file
4 - Comment out the line similar to the image below
This might be a different value but it should be related to extension.
I am no expert but this process helped me solved similar problem.
In my case I got this error because I downloaded a thread-safe version of the dll (infixed with -ts-), but my installation of php was a non-thread-safe (infixed with -nts-). Downloading the right version of the dll, exactly matching my php installation version fixed the issue.
After Windows 10 XAMPP now I installed LAMPP (XAMPP) on Ubuntu. Windows XAMPP had a lot less to configure compare to MAC (iOS) but now with Linux Ubuntu I had a few more since there are more going in Linux (a good thing).
I confused and activated mysqli.dll (and mysql.dll: erase "#" in /etc/php/7.2/cli/php.ini
I started to get the PHP Warning: PHP Startup: Unable to load dynamic library message related to dll. I commented out mysql(and i).dll in the same file but the message didn't go away up until I commented out " " in /opt/lampp/etc/php.ini.
Looks like XAMPP reads php.ini file from /etc/php/7.2/cli and makes modification in php.ini of /opt/lampp/etc. (;extension=php_pdo_mysql.dll after ";" restarted Apache and no more any message.
I encountered a similar error. The mistake I made was to use the "controller" name as "Pages" instead of "pages" in my url.
In Windows, it could be a wrong path in "System environment variables".
"Path" to the php.exe directory must be the good one.
'C:/PHP/5.2.13/ext\php_mcrypt1.dll'
I'd say there's some typo on your php.ini (the extra 1). Perhaps you're loading a different php.ini from what you expect (see the output of php.ini to make sure).
Other than that make sure that php_mcrypt.dll and PHP:
Were linked to the same VC runtime library (typically msvcrt.dll for VC6 or msvcrt90.dll for VC9) – use e.g. the dependency walker for this
Are both debug builds or both release builds
Both have ZTS enabled or ZTS disabled
For libraries that depend on further libraries (DLLs), make sure they are available (e.g. in the same directory as the extension)
PHP should give you meaning errors if any of the first three conditions above is not satisfied, but I wrote those anyway because I'm not sure for PHP 5.2.
From C:\xampp\php\php.exe I got
Unable to load dynamic library ''
C:\xampp\php\ext\php_.dll (The specified module could not be found.)
I solved by commenting out
C:\xampp\php\php.ini
;extension=
I had the same problem when I tried to use php with sql server, when I added the sqlsrv libraries ... it gave me the error, after several days of researching there, I understood that microsoft does not support x64 in this case so what I did was install laragon x86 and use the corresponding libraries. I hope it helps with something
Go to system env variable and set the php ext dir path as
C:\xampp\php\ext
basically it's finding the ext directory and then locating it's file but it's unable to find the files becuase php path is set as different.

PHP - An external Class/library is accessible from apache but not from phpunit

I am using ZeroMQ socket library in my web application. I have configured php.ini so Apache can use ZMQ but I dont know how phpunit can use it.
Dont phpunit use the same php.ini which apache uses?
In phpunit I get following error.
PHP Fatal error: Class 'ZMQContext' not found in /home/idlecool/checker/testcases/checkerTest.php on line 53
Which php.ini file is used for Apache and command-line generally depends on your Linux distribution ; if using Debian or Ubuntu, you'll generally have :
/etc/php5/apache2/php.ini for Apache
and /etc/php5/cli/php.ini for command-line -- and PHPUnit runs as a command-line application.
But note that quite often (it's true on Ubuntu, by default), all .ini files from the /etc/php5/conf.d/ directory will be loaded in both Apache and CLI modes.
Which means that, if you want an extension to be loaded in both modes, you should create a .ini file in that directory, loading and configuring it.
For example, you could have a /etc/php5/conf.d/zmq.ini file, containing something like :
extension=zmq.so
(of course, you'll have to put the name of the right .so file)

Categories