Using mcrypt with phalanger - php

How to use a php extension like mcrypt? My first thought was to find mcrypt.php and simply include it (context.Include("mcrypt.php", false);), but of course that doesn't exist since it is written in C.
I was reading over Writing compiled PHP extensions in PHP post from the blog but that seems to be about creating your own extension for use in .net. But maybe Im wrong considering this statement: "Implement Phalanger extension in PHP langage. When you take your PHP library and compile it using Phalanger, the result is DLL working as any other extension"
But even still phpc (phalanger php compiler) is not going to compile c code as far as I know though I haven't tried.
these are the calls my php class is trying to make:
mcrypt_module_open
mcrypt_enc_get_key_size
mcrypt_enc_get_block_size

mcrypt is not yet reimplemented as managed Phalanger extension ... if you know some opensource alternative I can help with porting to Phalanger Extension.
For now, you can use native alternative (so you would have to run in x86). Simply open your .config (web.config for web app, or create app.config for desktop app), and add following
<phpNet>
<classLibrary>
<add assembly="php_mcrypt.mng, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4ef6ed87c53048a3" section="mcrypt" />

Jakub Míšek's answer is definitely right and if this post helps you please vote him up as well. However I wanted to simplify what he said as his advice still took me some time to understand what he was saying. Also please Jakub if you get a chance to read this correct me if Im wrong about anything.
First thing that got me about his answer was this file
php_mcrypt.mng
mng what is that????
But after digging through their [Phalanger] svn and the files located in
C:\Program Files\Phalanger 3.0\Wrappers
I found the mcrypt file. Also with some help from the php chat room I got a clue as to what the mng was, Managed Code.
So after adding the file as a reference as well as editing the web.config file to include it (as Jakub shows)
<phpNet>
<classLibrary>
<add assembly="php_mcrypt.mng, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4ef6ed87c53048a3" section="mcrypt" />
</classLibrary>
<scriptLibrary/>
</phpNet>
These lines must be feeding into Phalanger to load this extension when compiling (I think/know).
After that everything seems to compile and run fine! Thanks Jakub

It's not that complicated install and use MCrypt. For *nix users PHP.net provides a source of information in this page.
But for Windows there is not too much information.
However it's easy too. You just have copy the file libmcrypt.dll from a PHP Binary, save it in ext directory and enable it:
extension=php_mcrypt.dll
Note: In WINDOWS environment PHP EXtensions are usually anemd as php_ so you have to rename the DLL or the PHP.INI line above.
After that, restart Apache.
But before you do this, check your phpinfo() first because some packages and/or distributions comes with a pre-compiled static MCrypt.
Run it and check for with-mcrypt=static and/or MCrypt group with mcrypt support enabled

Related

Unable to load dynamic library 'php_grpc.dll'

My goal is to connect my laravel project to firestore firebase. I will be needing the grpc in order to continue it. However my problem is the .dll cant be found. I already uploaded the .dll file in ext folder.
I also included it in my php.ini file.
still getting the same error
I dont know if its the version og php and grpc is conflicting.
After applying the comments' suggestions:
You need to mention extensions without php_ and .dll prefix and suffix like below:
extension=fileinfo
extension=grpc
Restart Apache server if required. You can also check for php version on the command line using php --version. If it shows the version without any warnings/errors, it means the extensions are loaded correctly.
Also, as the error message in your screenshot suggests, you need to install the right thread safe package of GRPC relevant to your operating system architecture and PHP version from https://pecl.php.net/package/grpc
Since nice_dev pointed out it was a compatibilit issue. I downloaded the non thread x64 and used it. It worked. Been using the x84, maybe the reason why it's not working.

Linking phpcpp fails when building PHP extension

Environment:
I am trying to develop a PHP-CPP extension and have downloaded the the empty extension file from https://www.php-cpp.com/documentation/your-first-extension to start. I have also modified the makefile's INI_DIR variable to point to the correct path.
Problem:
When I try to make the empty extension it fails to create the shared library file and says /usr/bin/ld: cannot find -lphpcpp.
I'm pretty sure I have php-cpp downloaded correctly, so I have no idea what's wrong. (I have also searched the internet and have found no solutions)
PHP version: 7.4
System: Elementary-OS (Ubuntu)
Turns out that when I first ran make to compile php-cpp it didn't make the libphpcpp.so file. So, I reinstalled it from Github and built it again and it worked. I don't know why I didn't try that the first time.

Configuring php-cs-fixer and PATH variable

A while ago, I successfully configured Atom to beautify my PHP using php-cs-fixer, but now I need to go through the same process on another Mac and can't remember exactly how I did it.
As a front-end dev, I'm not a PHP expert, but I understand that the Atom plugin is merely the middleman facilitating the actual fixing using php-cs-fixer, which, by default, it doesn't have access to. Once I installed the fixer, I had to add its location to my PATH variable. The confusing part is that I don't have the fixer installed via Atom (checked ~/.atom/packages) nor Homebrew (confirmed with brew list), however, the file is present in /usr/local/bin. If I move it, Atom returns the original error, so it's definitely using this file:
See https://github.com/FriendsOfPHP/PHP-CS-Fixer for program installation instructions.
Your program is properly installed if running 'which php-cs-fixer' in your Terminal returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable.
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=php-cs-fixer&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.
Hide Stack Trace
Error: Could not find 'php-cs-fixer'. The program may not be installed.
at PHPCSFixer.module.exports.Beautifier.commandNotFoundError (/Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:204:14)
at /Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:304:22
at tryCatcher (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:510:31)
at Promise._settlePromise (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:567:18)
at Promise._settlePromise0 (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:612:10)
at Promise._settlePromises (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:687:18)
at Async._drainQueue (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:148:10)
at Async.drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:17:14)
at process._tickCallback (internal/process/next_tick.js:103:7)
which php-cs-fixer returns /usr/local/bin/php-cs-fixer and my PATH variable currently contains /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ourcore/.atom/packages/php-cs-fixer.
I guess my questions are, how is the fixer working if the PATH variable seems to be pointing to it in a different location, and how did it end up where it is? Does the location in my PATH matter at all, or does the Atom plugin know to look in /usr/local/bin? I just want to fully understand the entire process before repeating it.
EDIT: On further testing, I removed the Atom directory from my PATH and it didn't affect the plugin, so then I copied the file into the same directory onto the second Mac and it ran without issue, without needing to edit the PATH. Does the fixer file someone inform the OS?
Well first test "which php-cs-fixer" or "where php-cs-fixer" (depending on what os you're running) and if nothing is returned in the terminal then there actually is something wrong on the installation and the best thing to do is to manually install it.
Head to https://github.com/FriendsOfPHP/PHP-CS-Fixer and download it from there and follow the installation steps, after that it should all be good

PHP won't parse MySQL statements

I just installed Apache 2.2.15/PHP 5.3.2/MySQL 5.1.44 on Windows Vista. Apache is working fine, PHP is functional, and MySQL works on the CLI. However, when I try to access MySQL via PHP, I get an error (Fatal error: Call to undefined function mysql_connect()). extension=php_mysql.dll and extension=php_mbstring.dll are uncommented in the php.ini file, and PHP is in the system path. There is no libmysql.dll in either the top level PHP directory or the ext directory. There's a libmySQL.dll file in the MySQL bin directory (which is also in the system path); I tried renaming it, but that doesn't do anything
Also, in case anyone wants to know, I originally installed PHP using the MSI installer, but it was missing some DLLs, so I installed from the zip file.
I think I've exhausted all my options. Any help on this problem would be very appreciated.
Thanks in advance.
IIRC the msi installer sets some registry values that influence the php configuration, see http://docs.php.net/configuration.changes#configuration.changes.windows. That might change the location of the php.ini that is used. You might want to delete those registry keys. Anyway, you did edit the file that is shown in the output of phpinfo()?
Which build of php do you use? The one you can download from http://windows.php.net/download/? Then you probably have the new mysqlnd transport driver built into the php core dll and don't need libmysql.dll. The mysqlnd driver should show up in the output of phpinfo(). Does it?
It sounds like you do not have the MySQL mod for PHP properly installed or configured. I recommend using AMP on Linux, so sorry for not having any specific instructions for Windows.

How to unzip files using PHP if safe mode is on and you can't install extensions?

Are there any PHP-scripts out there that can unzip regular zip-files? The requirements we have is that we must run with safe_mode on and we're not allowed to install any extensions to enable this functionality. Thus, any functionality must be regular php scripts.
Any thoughts?
EDIT: Unfortunately, neither of the posted solution works for us. We may not change the safe_mode requirement unless switching hosts, which is currently not an option.
pclzip.lib.php is a fairly popular and well used php class that is able to extract zip file susing pure php
http://www.phpconcept.net/pclzip/index.en.php
The usual answer here is this or this. However, according to the PHP documentation:
PHP 4
The bundled PHP 4 version requires » ZZIPlib, by Guido Draheim, version 0.10.6 or later
PHP 5.2.0 or later
This extension uses the functions of » zlib by Jean-loup Gailly and Mark Adler.
So, both need external dependencies.
Have a look at http://www.phpclasses.org/browse/package/2495.html
It uses the gzip extension but that's installed on almost every server (I hope, check with phpinfo() )
Can't you ask them to disable safe mode for a single folder using a .htaccess directive such as:
php_value safe_mode "0"
and put the unzip script in there?
If so, then something like:
$output = shell_exec('unzip /path/to/file');
Would do it
If you are running on linux/unix you can run
exec("unzip file.zip");
Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir.

Categories