PHP and EXE files - php

When I searched for a way to execute a PHP script within another PHP script, I found the function passthru() at http://www.php.net/manual/de/function.passthru.php. I scrolled down and saw something with the registry, command line and EXE files. Is it possible to run a EXE file from a PHP script (with passthru(), exec() or something else) on a server.
If it is possible, is there a way to get the result or output of the EXE file?
And if all works, is there a way to use .NET applications?
Thank you in advance :)
I'm sorry, if my English isn't very good.

According to the manual passthru() does whats on the label, it passes trough stdout. If there is a browser on the other side it gets directly send to that.
If you want the results you could try backticks, this works because PHP is loosely based on Perl. :)
So, for example:
$foo = `mybinaryprogramm someparameters $somemoreparametersrightfromavariable`;
#now go and do something usefull with $foo
I should mention that you should sanitize $somemoreparametersrightfromavariable somehow, but i hope that you see that as good practice. :)

Related

How to write a PHP extension to work with the console program?

There is a console program for morphological analysis of text https://tech.yandex.ru/mystem/.
Work with the program from the console is simple:
./mystem -lwd in.txt out.txt
I need to carry out a morphological analysis of the text by means of PHP, use the exec () function is impossible.
The easiest way, using PHP to write text to a file, then using a bash script and cron to analyze and save into another file.
But I would like a more convenient option as a PHP function mystem (string, param).
Compile and install extensions I can, but do not know how to write them.
I think the problem is very simple, because maybe someone is faced with the decision of this problem is the "fish"?
Total my question is, Does anyone have a ready solution where you can change only the name of the console program and the expansion will be ready? Thank U!

Does PHP have anything like Ruby's irb?

If I want to try out something new in Ruby or Javascript, I love getting immediate feedback from irb or the JS console in Firebug.
Is there anything like that for PHP?
Update
As #bernie pointed out, such tools are called REPLs - "Read-eval-print loop"
Run php -a in the command-line. But this does not work on Windows.
For Windows, you may want to try phpa-norl.
Yes, there is a way: php -a,
-a means interactive shell
php -a is the closest thing I know of but it's not quite like irb. irb will execute each line at a time. php -a will wait until you press ctrl-D (for end of line) and will then execute all lines.
How about phpsh? It's not fully compatible with PHP, but it represents a serious effort.
http://www.phpsh.org
Boris
I'm not working with PHP currently, but I just spotted this online and remembered I had once asked this question. Boris looks very nice.
https://github.com/d11wtq/boris
If you have a Mac, I find the PHP Code Tester program a much better way to accomplish the same thing: http://www.macupdate.com/app/mac/37328/php-code-tester

How do you run a command line program (like lame or svn) with PHP?

Specifically, I need to automate the encoding of audio files into mp3 with LAME. You don't need to know LAME to answer this, I could be talking about svn or some other program..
I know how to use LAME on the command line to do this, for one file at a time.
I would like to do this via a php script however, so I can convert a bunch at once (for instance, all the files in a directory)
So what I am confused about, is how I should invoke the program, LAME. I could definitely use
shell_exec()
http://php.net/manual/en/function.shell-exec.php
But is that a "screwy" way to do it, since I am going through the shell?
Should I be using lame_enc.dll somehow instead, instead of lame.exe?
It seems like I could somehow do it with exec() also http://php.net/manual/en/function.exec.php
But in that case, how would I supply the arguments?
Or is there a better way to do it, maybe a .bat file? I am running windows
Should I be using lame_enc.dll instead of lame.exe somehow?
You can use exec() and specify arguments just like you would on the command line. Other options are outlined on the Program Execution manual page for PHP.
It's possible to do it with PHP. Not a typical use case scenario but it can be done. Since you are on Windows, a bat file would be better suited since then you don't need the PHP parser to run the script.
Put the same commands you would run in the console to convert your audio files with LAME in a *.bat. Then run the bat as if it was a regular executable file.

Calling a system() command and bringing back the results

I need to put several thousand large files in a folder into a RAR archive several times a day. I used to do this manually via sFTP using a custom command with the RAR software package.
I'm wondering if it would be possible to use the RAR command using system() in PHP, and bring back the results every second or so to get a clear indication of how far along the process is.
When you use the RAR command, it draws a progress bar in the terminal window much like wget. I want to grab that progress bar and somehow display it on a page.
Any ideas on how I could do this?
Thanks :)
You can use the PHP popen() call to execute a process and read its standard output. That will get you the progress bar. However, using the PHP builtin rar support might get you a more robust solution with better information on what went wrong and why.
if you stick with system() then the best you can do is get the return code back from the process. Find out what the return code is for success. Use it to determine if your operation was, in fact, successful.
If you use exec() or passthru() you can get the output of the command as well.
You might be able to get the progress bar using some magic with popen(), but I am not sure.
Yes may be popen() is useful. You can get the output and parse it to get the results.

Calling fcsh from PHP script

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.

Categories