I am trying to use PHP's printer functions. But PHP gives an undefined function error. I am using PHP 7.2 so I looked for a php_printer.dll online but I only found for PHP 5.x. I copied it to PHP ext directory and added a line to my php.ini, restarted apache but it still is not working.
I wanted to be able to list all available printers on my network and choose one and print with it.
C:\xampp\php\ext\php_printer.dll
php.ini
extension=php_printer.dll
Here is my code
$ouput = 'Test print...';
$getprt = printer_list( PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED );
$handle = printer_open(getprt['NAME']);
if($handle) {
echo "connected";
} else {
echo "not connected";
}
printer_set_option($handle, PRINTER_MODE, "raw");
printer_write($handle,$output);
printer_close($handle);
Looking at the one issue on that git repo (https://github.com/gimjudge/php) I see that gimjudge has complied these DLL's for 32 PHP only. Their reasoning being that until PHP7 the 64bit PHP versions were actually only experimental. PHP only became truly 64 bit as of PHP7.0
So to use this dll you would have to install the 32bit version of WAMPServer. Then you will probably have no problems activating this DLL.
You can download the 32bit version of WAMPServer 3 from here: http://wampserver.aviatechno.net/
Its the backup repo and much easier to see what you are doing and which version you are downloading than the normal SourceForge repo.
Make sure you have backed up all you site(s) and databases before installing the 32bit WAMPServer.
However it is possible to install the 32bit AND 64bit WAMPServer on the same PC as the default folder names are different (C:\wamp or C:\wamp64) the Apache and MySQL service names are also different (wampapache or wampapache64) and (wampmysqld or wampmysqld64)
Although its not a good idea to start both at the same time as this will use a lot of memory for no good reason.
(Credits RiggsFolly)
Related
new php parallel. it's new and there is no troubleshooting about it anywhere and the only documentation about it, is php.net itself which is not enough.
this is what I did (per instructions):
installed latest version of WAMP(3.1.9 x64).
installed latest version of PHP(7.3.9) on WAMP.
added PHP to windows system environment path.
added pthreadVC2.dll to PHP folder & added pthreadVC2.dll to windows system environment path.
added php_parallel.dll to php/ext directory.
added extension=parallel to php.ini.
restarted everything.
<?php
# this is my code
$runtime = new \parallel\Runtime();
$future = $runtime->run(function(){
for ($i = 0; $i < 50; $i++)
echo "$i";
return "easy";
});
for ($i = 0; $i < 50; $i++) {
echo ".";
}
hours spent. now windows cmd says: "Fatal error: Uncaught Error: Class 'parallel\Runtime' not found in ...[my file address]" and wampserver says "The connection was reset (firefox error)" only on the page I use parallel\Runtime and the other pages work fine.
and please with all do respect don't mark my question as broad one or any other things if you simply don't know the answer. at least show me some links.
As far as I can tell, to install an extension from a .dll provided by PECL, the following need to match between your extension and your PHP build, found in phpinfo():
PHP Version: Found in PHP Version
Thread Safe: Found in PHP Extension Build (TS=threadsafe or NTS=not-threadsafe)
Compiler Version: Found in PHP Extension Build (eg: VS15 or VS16)
x86 vs x64: Found in Architecture
On the PECL repository for parallel, you should check latest updated version and the package names are self-explanatory, so you can choose your desired one, i.e. ... 7.3-ts-vc15-x64
Note (maybe does not apply now):
Given the limited builds of parallel, your PHP Build must be: 7.3+, TS, and VC15. Double-check that this is indeed the case for you by looking at your phpinfo(), and also be sure you are using the x64 version (since you said your PHP is x64).
The correct answer is JS_Riddler's post (Dated Dec 3 '19 and edited by T.Todua), but I wanted to elaborate for Windows users.
Before you install, on the command line, if you do "php -v", you may see something like:
PHP 7.3.33 (cli) (built: Nov 16 2021 14:49:44) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Don't let the "(Visual C++ 2017)" confuse you...it's the "ZTS MSVC15" that is important, indicating the thread-safe build and runtime library.
Also note the major and minor version numbers: "7.3" in the above example. The build number (eg the third number, '33' in the example) does not matter.
And also note the architecture: "x64" in the example.
The major version, minor version, and architecture need to match the version of parallel you download, so for the above example you would want to download
php_parallel-1.1.4-7.3-ts-vc15-x64.zip
Note: after downloading and unzipping the parallel archive:
copy the php_parallel.dll file to php/ext/php_parallel.dll
copy the pthreadsVC2.dll to php/pthreadsVC2.dll
add "extension=parallel" somewhere in your php.ini on a line by itself.
you should be able to run "php -v" from a command line. If you get an error, double check that the php.exe (and pthreadsVC2.dll) are on your PATH and that the php_parallel.dll version you have in the php/ext folder matches the major and minor versions of your php executable.
Another note: Many hosting companies do not use the ZTS version of php, so it appears this extension is mostly for CLI development applications at this time. Don't try to write production code that relies on it unless you know your target host supports it.
Error log turned out the saver.
PHP Startup: Failed to load .../php/php7.4.9/ext/pthreadVC2, The system cannot find the file ..
Then I've just removed .dll from file name, and then it gave:
PHP Startup: Invalid library (maybe not a PHP library) 'pthreadVC2' in Unknown on line 0
If I remember correctly, it turned out that WampServer (with it's builtin php) does not support multi-threading/safe-threading or like that, and it was not possible to use it on WampServer. However interesting thing turned out, is that it works in CLI.
I had the exact same issue. Also, I copied the file pthreadVC2.dll into the folder ext. When I moved this file out of the folder then it has worked fine.
Folders:
yourPhpFolder/pthreadVC2.dll
yourPhpFolder/ext/php_parallel.dll
I'm getting Call to undefined function printer_list() cuz my php_printer.dll isn't working and in the error log I'm getting PHP Startup: Unable to load dynamic library.
c:/wamp64/bin/php/php5.6.31/ext/php_printer.dll
I searched the entire web for php_printer.dll that works with php 5.6.31 and I didn't find it, I'm working with wampserver 3.1 on windows 7 can anyone help?
Looking at the one issue on that git repo I see that gimjudge has complied these DLL's for 32 PHP only. Their reasoning being that until PHP7 the 64bit PHP versions were actually only experimental. PHP only became truly 64 bit as of PHP7.0
So to use this dll you would have to install the 32bit version of WAMPServer. Then you will probably have no problems activating this DLL.
You can download the 32bit version of WAMPServer 3 from here Its the backup repo and much easier to see what you are doing and which version you are downloading than the normal SourceForge repo.
Make sure you have backed up all you site(s) and databases before installing the 32bit WAMPServer.
However it is possible to install the 32bit AND 64bit WAMPServer on the same PC as the default folder names are different (C:\wamp or C:\wamp64) the Apache and MySQL service names are also different (wampapache or wampapache64) and (wampmysqld or wampmysqld64)
Although its not a good idea to start both at the same time as this will use a lot of memory for no good reason.
I have followed the instructions here: PHP Install SSH2 on Windows machine amongst other places.
Please note I am at work and cannot change this development environment.
Using
if (extension_loaded('ssh2'))
I can see the extension has not been loaded.
I tried using both the TS and NTS files from here: http://windows.php.net/downloads/pecl/releases/ssh2/0.12/ for PHP 5.3 (I am version 5.3.5).
I am have placed php_ssh2.dll and php_ssh2.pdb files in the correct ext folder for PHP (I have confirmed this is the right ext folder using the phpinfo() command).
I have added extension=php_ssh2.dll to the php.ini file, again ensuring it's the right ini file using the phpinfo() command
I have added libsshl2.dll to both syswow64 and system32 folders
When I try to register either of those using command line prompts it fails but I have been told by my other question this is because libssh2.dll is not a COM server so cannot be registered - How do I register a php dll with windows if it's 64 bit windows but 32 bit php and apache? I have tried running the commands as the administrator
Apache has been restarted. There is nothing in the error log.
Please help, tearing my hair out over this one
honlestly i think youd be better off with phpseclib. libssh2 is notoriously difficult to use. its not well maintained and isnt even as feature packed as phpseclib is. more info on the advantages of phpseclib over libssh2:
http://phpseclib.sourceforge.net/ssh/compare.html
example:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>
Take a look at this answer.
It seems that for each version of php, you will have the exactly version of ssh2. You cannot run a ssh2 dll if it is not built with that php version
So check the version out, pay attention that there are two download links, for 32 or 64.
https://stackoverflow.com/a/16480426
I have a PHP application that is running under WAMP and using JPGraph. It all works fine. I am trying to now deploy the application on a production web server which, rather than running WAMP, runs native Apache and PHP, and am receiving the following error:
Notice: Use of undefined constant IMG_PNG - assumed 'IMG_PNG' in C:\Program Files\Adaptive\webPortal\models\jpgraph\jpgraph_errhandler.inc.php on line 282
JpGraph Error: 25001 This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)
Now obviously I have ran up phpinfo() and, as expected, there is no GD enabled on the production server. The only difference I can see is in the version of PHP; WAMP is bundled with PHP 5.4.12 and the production server has installed PHP 5.3.29, so a slightly earlier version. The issue is this has to run on Windows, and I can't find a Windows PHP installation for any version greater than 5.3.29.
However, I see no reason why I can't just enable GD on the production server. BUT:
The extension=php_gd2.dll line is uncommented in php.ini
php_gd2.dll exists in \PHP\ext
So... yeah. I'm kind of stuck haha. Can anyone help? Thanks in advance!
I have Windows 7 64 bits, PHP 5.4.3 installed through WAMP 2.2 and imagick (ImageMagick-6.8.3-9-Q16-x64-dll.exe). I tried to use the php's dll of imagick from a lot of sources but all of them give this error in apache_error.log:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.4.3/ext/php_imagick.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0
Any thoughts on how to solve this?
perhaps this can help you:
step-by-step instructions for installing IMAGEMAGICK on WAMP?
and
http://www.elxsy.com/2009/07/installing-imagemagick-on-windows-and-using-with-php-imagick/
"Just to make things clear, all the PHP dll files (librarires) are 32 bit, so if your system is 64 bit and you will still need to download and operate 32 bit ImageMagick, Apache, etc."
I went through the same pain. Win64+php-x86. It ended up being something relatively simple to fix - it is all about paths.
I first had installed the full ImageMagic-x64, then eventually the extension. I later noticed that installer had appended ImageMagic in the beginning of the PATH.
Just in case I tried with the x86 version and got different errors about missing DLLs.
So, just in case I uninstalled ImageMagic completely and cleaned up all references to it from the environment (it was in the PATH and MAGICK_HOME).
Then I installed just the extension (in my case from http://windows.php.net/downloads/pecl/releases/imagick/3.1.2/ I got php_imagick-3.1.2-5.4-nts-vc9-x86.zip) and unpacked it in the ext folder.
The revelation came after I tried to run this from the command prompt: php -i and got an error that it could not find CORE_RL_wand_.dll - but I did see it in the ext folder!
Adding C:\Progra~2\PHP\EXT at the end of the PATH environment variable solved it (after making sure that there are no other DLLs interfering).
Note: I used the 8.3 path to "C:\Program Files (x86)\php\ext" - just in case as I've seen PHP being sometimes picky and unable to resolve paths with spaces in them.
Also - after messing up with the PATH you may have to reboot the PC - in my case it worked from a command prompt right away, but IIS had a cached (older) path.
In conclusion: I suspect the PHP extension relies on some DLLs (which it delivers as part of the ZIP) but the same ones are also part of the standard ImageMagick installation, except that the two are not exactly the same - if you happen to be loading the wrong ones fun things happen...
For a 64bit WAMP (PHP 5.4.x, PHP 5.4.12 thread safe in my case) a working combination is the following:
ImageMagick-6.8.7-8-Q16-x64-dll.exe or possibly latest Q16/x64/DLL from here: Link
and php_imagick-svn20120508-5.4-VC9-x64 from here: http://www.mediafire.com/php-win64-extensions