I'm creating an app using CodeIgniter, but I'm unable to run Linux commands using my PHP script.
How do I run terminal commands?
I've tried shell_exec() and exec(), but both don't work while using CI.
That depends on your server configuration if the functions are disabled, you need to enable them in your php.ini. Here are some alternatives:
popen()
or if you need an interactive way try proc_open()
system()
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 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.
I want to extend the automation of the PacketETH program CLI using PHP
It can be done in GUI however this still means a user has to do it
Is it possible to have the packetETH run and a PHP deliver instructions, and then receive results back for manipulation?
In a broader sense, is this type of connection possible at all?
Thankyou
You can access the command line from php by using the Php System Program Execution functions. http://php.net/manual/en/book.exec.php. You can try out the exec function. It lets you execute shell commands.
To run the packeteth program from php you can use a command like the following:
exec("/path/to/packeteth/packETHcli -i lo -m 1 -f packet1.pca");
Is there any alternative for PHP exec(), shell_exec(), system(), passthrough() functions? As all these functions have security risk, need a way to execute server commands without using any of these functions.
Due to security reasons, can't enable these functions on my server php configuration. But as per website requirement, I need to execute some external commands like server ssh commands through php script. So, if there are any alternative ways to achieve same then please reply back to me.
You can write shell or bash scripts and invoke them through cron or set a daemon and let it check for a specific flag in database if you can do that.
In PHP 5.6 is it possible to disable safe_mode? First I want to do it locally. I am using XAMPP and Windows. I have tried to find safe_mode in php.ini but not found.
I want to execute mysqlcheck -c eximstats this kind of command from script in server. What i have done so far is tried exec(), system() but not worked. This is why i need to disable safe_mode.