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.
Related
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.
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.
I have modules written in python. And I am running my webserver through php apache server. For invoking the existing python scripts, I'm using the following command and this works fine,
shell_exec("python.exe file.py args");
Is there a proper way apart fro doing shell_exec / exec comnand from php.
There are two ways to do that.
Integrate Python into PHP. PHP supports C extensions while Python has libpython. I do not know if such extension exists. This approach doesn't require additional processes to start, but it is total madness.
Run Python script as a service and instead of shell_exec() call some REST API (or whatever). This approach requires additional entities such as services, sockets, but it seem to be architecturally correct.
Is it possible to create a shortcut that points to in-existing file in php and make it run normally in windows?
Example
makeshortcut("C:\Windows\calc.exe","short.lnk");
Then when I download the shortcut, it would open calc on my computer.
I don't have COM enabled, I do have exec() enabled, so I can run some kind of perl or python, however, lots of extensions are disabled, particlarly (pywin32 and win32::shortcut), so it would be highly appreciated if I can do this only in php or using calling another script with exec() which doesn't require me to install additional extensions.
The linux ln command has nothing to do with Windows .lnk files, and they are not compatible.
Here is some info on the .lnk file format.
As you can see it is not trivial to create from scratch.
liblnk library allows you to read .lnk files in Linux, but I haven't seen one that allows for their creation.
Edit:
Here is a SO question similar to yours:
Generate Windows .lnk file with PHP and Creating a Desktop Shortcut Using a Web Page
You can use http://www.mamachine.org/mslink/index.en.html - a bash and c program to create a shortcut.
Compile the C program for your platform and call it with the shell_exec function.
Even if the question is old, I hope it helps others.
My web sites are hosted on Total Choice Hosting using some kind of Linux (I don't know what precise variety) and Apache. I don't have command line access - I can run command line programs only via exec() in PHP, or via CRON jobs.
Can I install and use PDFTK on a system like this?
If so, what exactly do I have to do? Which files do I have to copy where? Do I have to rebuild PDFTK from source, or is there an executable version somewhere?
Since (as I understand it) PDFTK is based on iText, which is written in Java. Maybe I'd be better off using the original iText package?
Or is there a better way of doing what I want to do (which is basically to merge and flatten a PDF file (blank form) with a FDF file (field values) into a new PDF file (the completed form) and download it to the user)? Is there some native PHP or Python or Perl code to do this?
Thanks - Rowan
A quick glance reveals that the PDFTK source is C++ and it looks like they use GCJ to compile some 3rd party Java code to native code. If you find a pre-built version of PDFTK that matches your OS and architecture you should be able to just upload the binary to your system and run it from PHP using exec. There are some builds available on the install page.
There are some native PHP libraries available for creating and manipulating PDFs. Check out TCPDF, Zend_Pdf, and FPDF to see if any of those are usable. Each one should support what you want to do, its just a matter of choosing the right solution.
Using PDFTK may be the fastest option since it is compiled code, but it is the least portable option since it would require the server have that software installed on it, where the PHP solutions could be distributed with your code.
If you are on a shared host you cant install PDFtk because you don't have access to root to install anything. You need to have a host that has it preinstalled. I use bluehost.com but there up-time is not the best. It works for now but I am going to move to another host once my site is complete. I have had several outages that have lasted for over a day.