PHP ImageMagick script not working when executed via command line - php

I have a PHP script I'm trying to execute via the command line using the exec() function and I'm getting errors saying PHP can't locate the various classes that are part of the PHP ImageMagick extension (PECL is what I'm using) but it is installed correctly and works fine when running other scripts that use it via the browser.
I'm executing my code this way to create multiple instances and essentially cause parallel processing by allowing Linux to optimize the various processes across my CPU cores on its own. It works great for all the other things I use it for, but not in this situation.
Do I need to change how I installed Imagemagick?

PECL Extension was missing from CLI INI File. Apparently there are two of those files, on for browser execution and another for command line interface.

Related

Possible to "tunnel" PHP extension from Docker to outside?

On a CentOS 7 Virtual Machine, I have a PHP script running in Apache. That PHP script requires a PHP extension which I cannot install on the Virtual Machine. However, I have found a Docker image which contains the extension I need.
Now, how do I proceed from here?
Is it somehow possible to "tunnel" the PHP extension from inside the Docker to its host?
Or is it wise to make a detour over the command line? I.e. in the outer PHP script, call a system command which runs the Docker image, which runs a PHP script with the extension I need.
possible? yeah, make some api doing the required actions inside the VM, serialize the result, and deserialize it where your main app is running. the serialization process may be done with serialize() or json_encode() or var_export(), the transfer protocol can trivially be implemented using HTTP or HTTPS (just use apache or nginx?). PS, you may want to add some authentication or ip whitelist.
am curious why you can't install the extension on your main system tho, i guess it's' a windows<->linux compatibility issue?

Python on a shared hosting server

I have a hosting plan through Godaddy that only supports python 2.6.6. I have been able to install python 2.7 and 3.6 through SSH and run scripts, pip, no problems.
When I try and run a PHP script that calls a python script from SSH, it works just fine using my new python installs, but when I open the PHP script in a browser, it will only run 2.6.6.
Why is this? Is there a way to get around this without getting a VPS?
I think what is happening here is that you are able to manually run Python3 from your SSH session by calling it directly.
However, your PHP installation probably isn't aware that you have more than one instance of Python installed. At a guess, your PHP installation is defaulting to it's environment path (or other predetermined library directory) where it can find a Python installation (this installation being the original 2.7).
I'm not sure how you are calling your Python scripts but there is an answer here: Calling specific version of python from PHP that talks about changing the python version in the script.
Another possible solution is to add the directory containing Python3 to your $PATH variable. Word of warning, if this is a shared system this might be disabled or potentially COULD get you in some trouble. Since altering the path might start other python scripts (belonging to other people) being called by Python3, which could break them (due to deprecated syntax etc)
When you want to start messing with system configuration, you're getting into VPS territory rather than shared hosting.
I have found a sneaky way around this. I used SSH2 PHP extension to call the python3.

Run a C++ Application on a Webserver with WordPress

I have a C++-library (.so) for some calculations that I would like to call from Wordpress/PHP via an input formular. The promising idea to build the .so-library as a PHP extension using PHP-CPP has been fine locally on Ubuntu 14.04. But on the webserver this method failed because my webhoster doesn't support changing the extension directive in the php.ini/.user.ini. I see the following alternatives:
Build an exutable application and run it from PHP via proc_open() and send a lot of variables to the stdin of the application. Wordpress itself offers PHP plugins.
Redirect to another server where my own php extensions are supported.
Is there a way using python/web2py for that purpose?
Which would be best?
Or any other ideas?
Probably the simplest way is to create command line utility in C++ and execute it from php with shell_exec. I tried that in past and the performance was not too bad.
"Probably the simplest way is to create command line utility in C++ and execute it from php with shell_exec. I tried that in past and the performance was not too bad."
This did help. Finally I managed a build on Linux which was portable to the webserver where the website and wordpress are located. The call to the binary built from C++ was done with shell exec or popen in PHP (which one I don't remember, it was in 2018). The PHP code was finally migrated to an own wordpress plugin. Unforunately, I could not use PHP-CPP due to missing admin rights for the webderver. But the integration via shell exec or popen works fine.

Does PECL Stem Work with PHP CLI?

I'm trying to build a background process that stems words using PHP CLI. I originally have used this stemmer, written in c (https://github.com/hthetiot/php-stemmer) - the problem however is that it will not work when executed via command line, only via the browser. I get an undefined function error. Before going threw the process of adding in a new module, I was hoping someone using it might already know if this is even possible. I'm aware of pure PHP implementations, but prefer the speed of a c extension.
Just found my system has two separate php.ini files, one for CLI, the other Apache. Just had to add the extension to the CLI ini.

PHP version is 4.4.9 when using exec() How do I change it on media temple without using .htaccess

I am using php version 5.3 on media temple's grid server, however when I call a file using exec() the page is executing in PHP version: 4.4.9
The reason I am using exec() is to process the file in the background.
This is probably a simple question, but how do I manually set the PHP version to 5.3 for this file without using .htaccess?
Thanks.
The PHP interpreter you invoke via exec() is often a CGI version installed on the server as /usr/bin/php. You need to find out if a more contemporary version is available and then call the interpreter explicitly:
exec("/usr/bin/php-5.3 your-script.php &");
# or just adapt your scripts shebang #!/usr/bin/php5
(Just an example, the filename will be different. Also you can usually leave out the path. It's mostly just security relevant for setuid binaries.)
You might find out about other versions via print_r(glob("/usr/bin/php*")). But asking your hoster might be a better idea.

Categories