I have Xampp installed and want to work with sockets in php, so I started with the sample code from http://php.net/manual/en/sockets.examples.php on localhost.
I got this well known error:
Fatal error: Call to undefined function socket_create() in
C:\xampp\htdocs\simpletcpipserver.php on line 14
After searching the web I changed the PHP.ini files:
I removed the ; from extension=php_sockets.dll and edited this part to:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = C:\xampp\php\ext
php_sockets.dll is present at that location.
But still I get the same error.
I did see this on http://php.net/manual/en/sockets.installation.php:
The socket functions described here are part of an extension to PHP which must be enabled at compile time by giving the --enable-sockets option to configure.
Apart from what I already did, I don't understand what this means.
Would should I do now to get the sample code to work?
Related
Using php 8.20 X86 Win32 VS16 not thread safe
In PHP.ini I have
extension=mbstring
(i.e. uncommented ";" in front)
and
extension_dir = "D:\webserve\php8X86Win32VS16NTS\ext"
In file system I have:
file php_mbstring.dll
in:
directory D:\webserve\php8X86Win32VS16NTS\ext
...
PHPInfo()
states it is using the php.ini file I have edited.
extension direct is "ext" (which it is if if I use fully qualitfied
path in php.ini)
...
Yet I still get error in code:
Uncaught Error: Call to undefined function Stichoza\GoogleTranslate\Tokens\mb_strlen()
...
What is the next thing I should check in my configuration to get multibyte string support working in PHP?
I wanted to use some extensions of PHP 7.1 after installing it and Apache 2.4 and on my Windows 7. I wrote a small test script index.php to call some functions of the given extensions.
<?php
var_dump(mb_strlen('p'));
var_dump(mysqli_connect_error());
and uncommented the appropriate lines from the php.ini, like
...
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysqli.dll
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
...
and configured the extension_dir according to the windows-specific part of the php.ini
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
extension_dir = "ext"
I restarted the Apache web server and fetched the http://localhost/index.php. I got the error messages:
Fatal error: Uncaught Error: Call to undefined function mb_strlen() in C:\Program Files\Apache24\htdocs...
which means the extension was not loaded.
I doublechecked that the php.ini I made the modifications in is the same as the phpinfo() displayed in the browser:
Loaded Configuration File C:\Program Files\php\php.ini
On the contrary, if I started the same index.php not via web server but from the command line then I got different output:
C:\Program Files\Apache24\htdocs>"C:\Program Files\php\php.exe" index.php
int(1)
NULL
which means the extensions were loaded properly.
The command line PHP uses the same php.ini:
c:\Program Files\Apache24\htdocs>php -i|find "Loaded Configuration File"
Loaded Configuration File => C:\Program Files\php\php.ini
How can it be that the same php.ini file loads the extensions from command line but does not load them when used via the web server?
Contrary to the description in the php.ini, the extension_dir should be specified with a full path, not just a relative one. Changing the line in php.ini from
extension_dir = "ext"
to
extension_dir = "C:/Progra~1/php/ext"
and restarting the web server solved the problem.
NB: I used the DOS-8.3 path instead of "C:/Program Files/php/ext" because according to the php-7.1.11-Win32-VC14-x64.zip\install.txt manual, it does not like paths containing spaces:
You may choose a different location but do not have spaces in the path (like C:\Program Files\PHP) as some web servers will crash if you do.
The path I referred to doesn't contain any spaces so I don't think I did anything wrong. Despite this, I am not sure how it would work if I had installed php to the default directory c:\php but it seems that defining the full path is a more secure way.
Check which modules is Apache using:
go to your apache config. IE: cd /etc/apache2/mods-enabled
list enables modulesls -lsai php* (in my case, prev version was enabled)
remove previous modules (IMC: rm php*)
enable needed module. IMC:
sudo ln -s ../mods-available/php7.4.load
sudo ln -s ../mods-available/php7.4.conf
reload apache (IMC: sudo /etc/init.d/apache2 restart)
use print/dump phpinfo(); to check which php module Apache is runnig
Command in example will work on Linux/Unix machines. Not on windows I'm afraid
So, I'm trying to use a table in a php program and I got a fatal error (class mysqli not found) which after researching on stackoverflow means I don't have extension=php_mysqli.dll enabled (here's the php-website which talks about enabling it: http://php.net/manual/en/install.windows.extensions.php.)
But I looked in my php.ini file and the sort of ";extension=..." lines that it talks about commenting aren't there (I did ctrl + f to search through as well as manually searching through). I tried just adding the "extension=php_mysqli.dll" line but it still didn't work.
Someone else also said you need to uncomment the extension_dir line in php.ini and specify my location but that line only appears in an if loop in php.ini and it's not commented out. (from this stackoverflow question: Fatal error: Class 'MySQLi' not found).
How do I add "extension=php_mysqli.dll" to my php.ini file so my php program can create a mysqli table?
If you don't have mysqli extension in you php version you should download another version of PHP.
http://windows.php.net/download/
Get PHP 7 OR PHP 5.6 last version (thread safe recommended).
After, following the instructions on this page http://php.net/manual/en/install.windows.extensions.php to activate mysqli extension.
;extension=php_exif.dll
extension=php_mysqli.dll // Uncomment this line
;extension=php_oci8_12c.dll
You can define the path of your php extensions folder if you have problems.
To do this, uncomment line extension_dir.
extension_dir = "C:\php\ext" // Your ext folder path
Restart your apache / nginx and try to use mysqli functions.
Hope this will can help you.
In my case, I had the extension=mysqli set in my php.ini and the php_mysqli.dll file in the php/ext folder, I just had to uncomment (remove the ;) the extension_dir line in php.ini:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
extension_dir = "ext"
Save php.ini and restart php and the webserver.
I'm trying to enable PDO for SQLite3 on php 5.4.19. Following this--> http://www.php.net/manual/en/pdo.installation.php
uncommented the line in the php.ini file that says:
extension=php_pdo_sqlite.dll
;added next line
extension=pdo.so
However, the phpinfo() still says:
PDO
PDO drivers no value
I would think it would like the SQLite driver would be listed.
Trying to troubleshoot so I also tried adding this to the php.ini file.
extension=php_pdo.dll
However, there is no such file in the /ext folder and it says this is no longer needed in this version of php.
What step am I missing?
Edit-->
Ok figured this out and it wasn't obvious to any research I did.
First, absolute paths were required which isn't documented anywhere that I could find. Final settings are:
extension=C:\php\ext\pdo.so
extension=C:\php\ext\php_pdo_sqlite.dll
extension=C:\php\ext\php_sqlite3.dll
[sqlite3]
sqlite3.extension_dir = C:\sqlite
Uncommenting extension_dir = "ext" in php.ini worked for me:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"
'phpinfo()no longer showsPDO drivers : none enabled' and shows PDO drivers : sqlite instead.
It also now shows sections for SQLite3 and pdo_sqlite.
First, try restarting your web server. If that doesn't work, check if extension_dir is set properly in php.ini. If that still doesn't work, check if the proper php.ini is being read in the phpinfo() output.
I am getting this exception when trying to run my PHP unit tests:
Fatal error: Call to undefined function openssl_random_pseudo_bytes()
What does it mean?
I had the same issue. I solved it by editing my php.ini file - changing ;extension=php_openssl.dll to extension=php_openssl.dll .
(For my installation, my php.ini file was located in my P:\Program Files\EasyPHP-12.1\conf_files\ directory.)
Your version of PHP wasn't compiled with the openssl module. If you are building from source, add the module like so:
cd /path/to/php-5.4/
./configure --with-openssl
It means you do not have the openssl extension enabled in your PHP install. It needs to be enabled for you to use openssl_* functions.
It means you possibly don't have openssl enabled.
If you are on windows its even easier to load it. Enable it from wamp icon on system tray.
Check your configuration php.ini:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
extension_dir = "ext"
extension=php_openssl.dll
Your php installation either does not have openssl enabled, or you could be running a version of php < 5.3.
To enable openssl, you must re-compile and install php with the "–with-openssl" flag. See php installation documentation
For me this error occurred because i had not configured openssl correctly for my PHP.
This is the exact step i followed to rectify this error.
https://stackoverflow.com/a/36070260/1221096