One of the improvements in PHP7.1 is that in Windows the readline extension is available out of the box. I'm having trouble using all of the functions though, as they don't all exist. The following code:
$functions = [
'readline_add_history',
'readline_callback_handler_install',
'readline_callback_handler_remove',
'readline_callback_read_char',
'readline_clear_history',
'readline_completion_function',
'readline_info',
'readline_list_history',
'readline_on_new_line',
'readline_read_history',
'readline_redisplay',
'readline_write_history',
'readline'
];
foreach($functions as $function) {
echo $function . (function_exists($function) ? ' exists' : ' does not exist') . PHP_EOL;
}
...produces the following output:
readline_add_history exists
readline_callback_handler_install does not exist
readline_callback_handler_remove does not exist
readline_callback_read_char does not exist
readline_clear_history exists
readline_completion_function exists
readline_info exists
readline_list_history does not exist
readline_on_new_line does not exist
readline_read_history exists
readline_redisplay does not exist
readline_write_history exists
readline exists
I can't find any reference in the PHP manual that only a subset of the readline extension's functions are available in Windows.
When I call php_info(), I get the following output:
readline
Readline Support enabled
Readline library WinEditLine
Is there some php.ini configuration setting (or CLI argument) that needs to be made in order to make all functions available? Alternately, is there some other way of making functions such as readline_callback_handler_install() available in Windows, or is the extension only half-baked?
Initially I thought that you might have been somehow falling through to an ancient PHP 5.0 which lacks those functions, but failing that I would have to guess that your PHP binary was compiled against an underlying library [or version thereof] that doesn't support the feature that those functions depend on.
Cross-referencing the list of functions that are missing with ext/readline/readline.c I would guess you're missing features corresponding to the constants/features HAVE_RL_CALLBACK_READ_CHAR and HAVE_LIBEDIT defined in ext/readline/config.m4.
TL;DR: Whoever compiled your PHP needs to figure it out. [probably]
For the record
PHP >= 7.4 to 8.1
yes:
readline_add_history
readline_clear_history
readline_completion_function
readline_info
readline_list_history
readline_read_history
readline_write_history
readline
no:
readline_callback_handler_install
readline_callback_handler_remove
readline_callback_read_char
readline_on_new_line
readline_redisplay
readline_list_history was added around during versions 7.2 and 7.3
Related
I write simple requirements checking script. It checks all required PHP modules installed. I need to check if pcntl is installed. But this module is accessible only in cgi environment and invisible for web queries. extension_loaded('pcntl') and function_exists('pcntl_fork') both return false. How can I perform this check?
Running php -i | grep pcntl will return the following if pcntl is enabled.
pcntl
pcntl support => enabled
If it is installed, the code bellow returns true
var_dump (extension_loaded('pcntl'));
Create a file called cli_supports.php
<?php
$supports = array();
if (function_exists("pcntl_fork")) $supports[] = "pcntl";
echo implode(",", $supports);
?>
Then from your feature detection scripts do.
$cli_features = explode(",", shell_exec("/usr/local/bin/php ".escapeshellarg(_DIR_."/cli_supports.php")));
If you're sure it's supported (or shared object exists) then check your php.ini and make sure it's loaded as an extension.
extension_loaded() should work (and what I prefer over function_exists()), and the only reason I can imagine it wouldn't is you not loading the shared object.
I found this http://www.php.net/manual/en/class.snmp.php, but I can't find link to download this script. I tryed to search in the WEB, but the same result.
Or is the any methods with php extension to make one session and work with it?
It is in the tarball. You can download it from the official website
Take a look into it:
$ tar jtf php-5.4.13.tar.bz2 | grep snmp
php-5.4.13/ext/snmp/
php-5.4.13/ext/snmp/config.m4
php-5.4.13/ext/snmp/config.w32
php-5.4.13/ext/snmp/CREDITS
php-5.4.13/ext/snmp/php_snmp.h
php-5.4.13/ext/snmp/snmp.c
php-5.4.13/ext/snmp/snmp.dsp
php-5.4.13/ext/snmp/tests/
php-5.4.13/ext/snmp/tests/bug60749.phpt
php-5.4.13/ext/snmp/tests/bug64124.phpt
php-5.4.13/ext/snmp/tests/clean.inc
php-5.4.13/ext/snmp/tests/generic_timeout_error.phpt
php-5.4.13/ext/snmp/tests/ipv6.phpt
php-5.4.13/ext/snmp/tests/README
php-5.4.13/ext/snmp/tests/skipif.inc
php-5.4.13/ext/snmp/tests/snmp-object-errno-errstr.phpt
php-5.4.13/ext/snmp/tests/snmp-object-error.phpt
php-5.4.13/ext/snmp/tests/snmp-object-properties.phpt
php-5.4.13/ext/snmp/tests/snmp-object-setSecurity_error.phpt
php-5.4.13/ext/snmp/tests/snmp-object.phpt
php-5.4.13/ext/snmp/tests/snmp2_get.phpt
php-5.4.13/ext/snmp/tests/snmp2_getnext.phpt
php-5.4.13/ext/snmp/tests/snmp2_real_walk.phpt
php-5.4.13/ext/snmp/tests/snmp2_set-nomib.phpt
php-5.4.13/ext/snmp/tests/snmp2_set.phpt
php-5.4.13/ext/snmp/tests/snmp2_walk.phpt
php-5.4.13/ext/snmp/tests/snmp3-error.phpt
php-5.4.13/ext/snmp/tests/snmp3.phpt
php-5.4.13/ext/snmp/tests/snmp_get_quick_print.phpt
php-5.4.13/ext/snmp/tests/snmp_get_valueretrieval.phpt
php-5.4.13/ext/snmp/tests/snmp_getvalue.phpt
php-5.4.13/ext/snmp/tests/snmp_include.inc
php-5.4.13/ext/snmp/tests/snmp_read_mib.phpt
php-5.4.13/ext/snmp/tests/snmp_set_enum_print.phpt
php-5.4.13/ext/snmp/tests/snmp_set_oid_output_format.phpt
php-5.4.13/ext/snmp/tests/snmpd.conf
php-5.4.13/ext/snmp/tests/snmpget.phpt
php-5.4.13/ext/snmp/tests/snmpgetnext.phpt
php-5.4.13/ext/snmp/tests/snmprealwalk.phpt
php-5.4.13/ext/snmp/tests/snmpset-nomib.phpt
php-5.4.13/ext/snmp/tests/snmpset.phpt
php-5.4.13/ext/snmp/tests/snmpwalk.phpt
php-5.4.13/ext/snmp/tests/wrong_hostname.phpt
The "SNMP" class (introduced in PHP 5.4) is not a "script"; rather, it is an extension that is either compiled into PHP or shipped as a module that can be enabled or disabled. I suspect that either (1) you are using an older version of PHP, or (2) you do not have the SNMP extension installed or enabled.
i need to determine the filetype of an file with php (5.3.7), no matter what filenameextension is used.
On Linux OS system i would use read the first Bytes from a file to find out the exact file type.
I think this is possible in PHP by using finfo
The Point is: my Server is not connected to the Internet, so I have to download the finfo PECL extension manually.
All that i found was this website: http://pecl.php.net/package/Fileinfo where the current finfo version is from from November 2006.
There is also an hint "his package has been superseded". But superseded by what?
If i take a look at this
http://www.php.net/manual/en/fileinfo.installation.php there is no information where i found this package.
The only thing i found there is "This extension is enabled by default as of PHP 5.3.0. " Does it mean, that this extension is part of every default >=PHP 5.3.0 installation? But if i try to use finfo commands, i get an Call to undefined function which looks like finfo is not installed, right?!
//Edit: by the way: i'm working on Linux, PHP 5.3.7
To answer my own question: I was on an wrong way for searching an new pecl file_info version.
For Linux Systems there exits an PHP package, which contains that extension, like this: php5-fileinfo-5.3.6-75.1.x86_64.rpm (depending on your Linux Distribution and PH Version)
To use fileinfo, you have install this package, like this:
#rpm -ihv php5-fileinfo-5.3.6-75.1.x86_64.rpm
When I check phpinfo(), I see /usr/local/php4/lib/php.ini
That means PHP4, right?
But When I execute the line of code below, it returns PHP5. WTF? I thought PHP4 did not have the DOMDocument class. I need to test for PHP4 and do a workaround, but this specific test is confusing me. Is there another more foolproof way to check for PHP4 in script?
if (is_admin() && class_exists('DOMDocument')) {
echo "PHP5";
} else {
echo "Awe PHP4";
}
The version of your PHP is listed right on top of any phpinfo() output. You can also determine it by echoing phpversion() or from CLI with php -v.
Apart from that, no. PHP4 does not support DOMDocument (at least not the one you are refering to). The old DOM XML extension has a similar named class though.
Try the following:
echo extension_loaded('domxml') ? 'old' : 'new';
phpinfo() is a cool function :)
edit, lots of similar functions here
http://www.php.net/manual/en/ref.info.php
you seem like you'd be interested in
phpversion() and version_compare()
The correct way to check your PHP version from phpinfo() is to read the header at the very top, but when doing checks in PHP code, checking php_version() is the way to do. There is also a predefined constant PHP_VERSION.
Well if phpinfo says you run php5 you are running php5. assuming by php_info you mean phpinfo.
you may wanna check the function phpversion
The path you are referring to is just the configured config file which could be anything.
You probably updated and kept it ages ago.
I'm wanting to print an xml file out as an HTML nested list using xslt, and as far as I know the code is correct, however I'm getting this error
Fatal error: Call to undefined function xslt_create()
Which I presume means the xslt functions havn't been enabled. How do I enable these functions within PHP? Is there a php file I need to include (like the way Javascript libraries work) or is it something more complicated? I'm hosted with MediaTemple.
Here's the php code I'm using:
<?php
// Allocate a new XSLT processor
$xh = xslt_create();
// Process the document, returning the result into the $result variable
$result = xslt_process($xh, 'armstrong.xml', 'familyToNestedList.xsl');
if ($result) {
print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
print " variable, the \$result variable has the following contents\n<br>\n";
print "<pre>\n";
print $result;
print "</pre>\n";
}
else {
print "Sorry, sample.xml could not be transformed by sample.xsl into";
print " the \$result variable the reason is that " . xslt_error($xh) .
print " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
?>
Thanks in advance!
Depending on your distro of linux, you may be able to just install the php5-xsl module, add the line "extension=php_xsl.so" to your php.ini file, and restart your apache2 server.
This worked for me on Ubuntu 11.10. You can input "sudo apt-get install php5-xsl" into the command line to install php5-xml.
You have to compile PHP with the support for it and make sure to have all the required dependencies. Please see the corresponding chapters in the PHP Manual for XSLT.
From chapter Requirements
This extension requires the libxml PHP extension. This means that passing in --enable-libxml is also required, although this is implicitly accomplished because libxml is enabled by default. This extension uses Sablotron and expat, which can both be found at ยป http://freshmeat.net/projects/sablotron/. Binaries are provided as well as source. Enable by using the --with-xslt option with PHP 4.
From chapter Installation
On Unix, run configure with the --enable-xslt --with-xslt-sablot options. The Sablotron library should be installed somewhere your compiler can find it. Make sure you have the same libraries linked to the Sablotron library as those, which are linked with PHP. The configuration options: --with-expat-dir=DIR --with-iconv-dir=DIR are there to help you specify them. When asking for support, always mention these directives, and whether there are other versions of those libraries installed on your system somewhere. Naturally, provide all the version numbers.
The recommended extension for using XSL transformations with PHP5 is XSL. If all you need to do is transform two documents, as show in your example, consider this example from the PHP Manual:
$xml = new DOMDocument;
$xml->load('collection.xml');
$xsl = new DOMDocument;
$xsl->load('collection.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
The transformToXML method will return the transformed document or FALSE, so you can keep the if/else from your code. In any case, it should be trivial to upgrade your code.
Well, is very simple, but on php.net its could be explained more explicitly.
I'm using one docker container contain ubuntu base and using php-fpm.
The steps to install this extension in my context were:
First search xsl extension on linux repository
apt-cache search xsl
I ended up finding the php5-xsl, so it was only install
apt-get install php5-xsl
that the installation process the setup configuration is already added, if does not happen, just make yourself
vim /etc/php5/mods-available/xsl.ini
insert this content:
extension=xsl.so
(obviously the paths are according to your php configuration settings, but my example is the default configuration)
Restart you php fpm and done!