i am trying to find a way to have a PHP script execute a .cpp file, and then return the results via PHP.
I will map out my methodology to avoid confusion in my question:
Certain action on webpage (Button click) -> PHP runs .cpp file -> the results of the .cpp file are returned to PHP -> returned data is used to repopulate the page .
Is this possible to do? (please do not vote down, i have looked online and could not find a solid lead to help me establish this connection)
I hope you mean to run a built executable...
The exec function will run the application similar to running it through a command line. This means that you can get the standard output of the application like you would through the command line.
How to run abc.exe using php
It's kind of kludgy, if you can, just duplicate the executables functionality in PHP.
Related
We've got a PHP code that is currently reading a config file to get some definitions and passwords.
The PHP code is out of my control and I cannot ask for code changes.
As I need the ability to change the config dynamically, I would like to execute a binary (written in go) every time the PHP code is trying to read the config.
The workflow that I think of will be something like:
PHP ask to read the file (fopen() for example) -> an executable is running and outputting the generated config -> the PHP code is getting the output as if it was reading a static file.
I'm not much of a Linux guru and I'm having difficulties understanding if it's possible or not and if it does, how to do it.
We're using Debian 9 and running PHP 7.2
Any ideas if it's possible and how to make it work?
ADyson's comment is quite worthy of consideration. If you insist on executing a program rather than asynchronously updating the file, this can be done: Create a named pipe with mkfifo config and continuously run the program, opening, writing to and closing the config in a loop. But you'd have to ensure that no two instances of the PHP code try to read at the same time.
I am looking to see if this is a possible scenario -
My php page calls prolog (and sends the query with data), and then prolog code runs and binds certain (output) variables, and then I take these variables and then load it into mysql db.
ie,
PHP -> call and send data -> Prolog -> execute goal and bind output variables -> send output variables into mysql db
I have seen a lot of documentation on how to "generate" html pages using sicstus and swi etc.. but this is reverse of what i want to achieve. any pointers?
thanks!
Based on my experience on previous projects where I had to connect PHP with Prolog I called Prolog from PHP using the php exec function:
exec("\"c:/program files/swipl/bin/swipl.exe\"" -f prolog_filename.pl -g your_query)
The exec function returns Prolog's output which you can you as you like(eg sending it to your mysql db).
You may need to edit the prolog path accordingly.
It's definitively possible to do what you're thinking about. For example
http://www.swi-prolog.org/pldoc/package/odbc.html
would allow you to work with a MySQL database from Prolog. However, I'm fairly certain that sending the output of your Prolog program back to php and then inserting it into mysql from the php side of things will make your life a whole lot easier.
Calling SWI-Prolog from a Web server could be done as illustrated by J.Paine here, but the preferred way of run SWI-Prolog on server side is, well... as a Web Server.
This because is simpler to debug the logic and getting formatted output using the extensive libraries that SWI-Prolog offers.
There is always the possibility to write a PHP extension module, the underling language is the same C, but this is clearly a difficult path.
Is it possible to know which PHP script is executing a certain mysql query?
I'm using a prebuilt system which has a bunch of files and I'm seeing one query I want to investigate but no idea where to start looking.
Thanks,
Try searching for non-variable parts of the query in the source files directly (e.g. using your IDE's search function, or using grep -r 'some part of the query').
If you can't find it, try tracing function calls with xdebug. This will log all PHP function calls, and it will be easy to find which file did mysql_query(the query).
(Set the ini setting xdebug.collect_params to 3 to get the parameter values in the log file.)
Need some help here. I have a c++ library for communicating with an embedded module (ArchLinux) via tty. This library was compiled/converted into php using swig.
The issue now is that a sample program written in php and run from the command line executes as expected but when this same code is used as part of a web page's functionality it fails to execute.
My assumption based on my limited linux knowledge is that tty requires a console in order to run which is why it fails to run as part of a webpage??
Does anyone have any ideas as to how I can get this to work? I have read something about using posix_ttyname but I cant seem to find any code samples that demonstrate its use.
I have attached the offending c++ files along with a test main.php which works for review.
Thanks everyone
http://www.mediafire.com/?ctblcvsy86mdg8p
$argv variable is available only when script is called from CLI. If you don't want to change the script so it could be called from web, you can try calling it from another script as
exec('main.php param');
Just like you do from command line.
My question is whether or not Flex's fcsh can be called from within a PHP script. Here is the background:
I have been created a simple process that creates a simple quiz/tutorial by converting a text file into a .mxml file and compiling to a .swf file using the mxmlc compiler. This works well from the command line, but I wanted to make the process easier by creating a web-interface to do this. My initial attempts with PHP's exec() function have not worked. The Python scripts I use to create the .mxml file work fine (using exec()), but I have not been able to get the mxmlc compiler to work.
After searching on the Web and on this site, I believe that using fcsh (instead of mxmlc) may be the way to go. Using fcsh would certainly compile the .mxml file faster (after the first run), and I think that fcsh can be launched as a service that might be able to be called from PHP.
On the other hand, maybe I am approaching this the wrong way. Would it be better to write a Flex application that calls fcsh and avoid using PHP?
Edit: Using fcshctl as hasseg suggested in his answer below worked very well. Thanks Ali.
The problem with calling fcsh from within scripts is that it works as an interactive shell instead of taking command-line arguments, compiling, and returning an exit status. There are different ways to get around this, which I've listed in this blog post of mine, where I mainly talk about fcshctl (which is my own solution for this,) but at the bottom of the post I've also listed other similar solutions to get fcsh integrated into nonstandard build workflows.
There are a few other ways in php to execute an external script. They are exec(), passthru(), system(), and backticks i.e. the key to the left of the 1 key. Each one has a different purpose and return mechanism.
You may have to put the command that executes your executable into a script and call that script via one of these functions.
Is there a particular reason why you can't use mxmlc directly? It seems like it would be easier to call than fcsh. Just specify all your compiler options in a XML file run it like mxmlc -load-config path/to/config.xml. You can find an example of the XML configuration format in FLEX_HOME/frameworks/flex-config.xml.