Author |
|
elt
Joined: 08 Nov 2006 Posts: 4
|
Posted: Wed 08 Nov '06 17:04 Post subject: Run executable from apache. |
|
|
Hello! I'm running apache as a web server without any other package like perl or similar. I want to run a little program i made to control the parallel port. But when I do this it wants to download the file on the browser. How do i make the executable run on the actual computer?.
Many thanks.
elt |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 08 Nov '06 17:19 Post subject: |
|
|
You need an interpreter like perl, php, ruby...or whatever to run your program. If you call the page with the programm only localy (http://localhost) you could also use vbscript. |
|
Back to top |
|
elt
Joined: 08 Nov 2006 Posts: 4
|
Posted: Wed 08 Nov '06 17:21 Post subject: |
|
|
Thanks for the very quick reply. I should have been more precise. I compiled this program with borland in c. so it's an executable as in an *.exe. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 08 Nov '06 17:24 Post subject: |
|
|
the *.exe is ok. But you need an interpreter to call that programm from a page
e.g. php
Code: |
<?php
passthru("C:/path/to/your.exe");
?>
|
Is there anything that your program returns? Some output for example? |
|
Back to top |
|
elt
Joined: 08 Nov 2006 Posts: 4
|
Posted: Wed 08 Nov '06 17:31 Post subject: |
|
|
You are on fire
What if i really don't care about some kind of output? Is there a way to merely let the executable to be runned? And if not. Is there an easy clickity way to install php on an already running server. Or would it be more easy to install some kind of package. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 08 Nov '06 18:11 Post subject: |
|
|
a) if there is text output like in the console, no problem PHP can show that output
b)installing PHP is ver easy. See http://www.apachelounge.com/viewtopic.php?t=570 for that.
c)Maybe can run your.exe as cgi, so there would be no need for PHP. |
|
Back to top |
|
elt
Joined: 08 Nov 2006 Posts: 4
|
Posted: Wed 08 Nov '06 18:25 Post subject: |
|
|
I went with B, thank you very much. I used exec() to avoid my console output. I now successfully turn off and on lights on through parallel port.
Cheers! |
|
Back to top |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Wed 08 Nov '06 18:49 Post subject: |
|
|
Just a warning with running executibles from PHP if you are using the Apache SAPI module, because of how Win32 threads, and because these modules run in a manner better designed for how Unix and Linux platforms thread, you may encounter your Apache server locking up or not responding, in which case you must KILL the two Apache processes and then START them again to clear it up. Please note that simply RESTARTing Apache will not clear it up.
I run a -very- busy web server with about 120,000 or more pages served each day, and I have had to re-code my site so that I use differing techniques that make calls from PHP as a CGI/FCGI to call outside executibles. My server would lock up sometimes 3 or more times in a day. CGI solves that problem very well.
I suspect that my busiest server handles over 300 EXEC calls each day. Only those that are processed through PHP as SAPI execution ever give me fits. Beyond EXEC this applies to: Virtual, shell_exec, Exec, back trick operators, and System functions.
There is quite a lot of info about this, and it is the only weakness that I see with running a PHP / Apache webserver on Windows vs Linux. But with FastCGI there are no disadvantages any longer. |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Wed 08 Nov '06 20:02 Post subject: |
|
|
If use broland C or Delphi you can write a true CGI program!
display a page with light on and a light off button.
the call the exe like /cgi-bin/some.exe?light=on or off, then read that variable an display the new output |
|
Back to top |
|
Cle
Joined: 10 Dec 2006 Posts: 3 Location: Dallas
|
Posted: Sun 10 Dec '06 1:54 Post subject: |
|
|
Hi James Blonde,
James Blonde: "c)Maybe can run your.exe as cgi, so there would be no need for PHP."
I have Apache2 and Windows XP to run a file name hello1.exe
Can you show me to configure directive or option to run a file with .exe, such as help from MG:
LoadModule cgi_module modules/mod_cgi.so
AddHandler cgi-script .exe
ScriptAlias /myfolder/cgi-bin "H:/myfolder/cgi-bin"
<Directory "H:/myfolder/cgi-bin">
Options +ExecCGI
</Directory>
I have these errors:
[Thu Dec 07 21:43:34 2006] [error] [client 127.0.0.1] (OS 5)Access is denied. : couldn't create child process: 720005: HELLO1.EXE
Thu Dec 07 21:43:34 2006] [error] [client 127.0.0.1] client denied by server configuration: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.icon
Thank you |
|
Back to top |
|
sbz
Joined: 30 Jul 2012 Posts: 2 Location: italy
|
Posted: Wed 01 Aug '12 8:57 Post subject: |
|
|
Hi Brian,
I think you described exactly the problem I have at the moment:
a .php script calls a file .exe using function "proc_open" and waits until the .exe script creates a .pdf file,
then .php script returns the .pdf file.
All seems to work well but sometimes apache locks up, even more times in a day.
When I find apache not answering web requests, I find many .exe processes hanged on,
but they are "locked" and they can't be terminated manually by task manager: I can only restart apache.
I already tried other functions like "exec", "passthru", ecc. but nothing changed and I can't use anything else to create that .pdf:
only that .exe script which is shared with other applications.
How did you solve the problem?
Please, can you help me step by step on how to call outside my .exe script?
Thanks a lot. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 02 Aug '12 9:47 Post subject: |
|
|
it would be nice if you could provide some example code to test with. |
|
Back to top |
|
sbz
Joined: 30 Jul 2012 Posts: 2 Location: italy
|
Posted: Thu 02 Aug '12 11:21 Post subject: |
|
|
this is my php script:
Code: | function cmd_execution($cmd) {
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w") );
$pipes=NULL;
$proc = proc_open($cmd, $descriptorspec, $pipes, null, null, array('bypass_shell'=>true));
if (is_resource($proc)) {
fclose($pipes[0]); // no input
fclose($pipes[1]); // no output
fclose($pipes[2]); // no errors
proc_close($proc) ;
}
return 1;
}
// GET file name
$name_pdf=$_GET['name_pdf'];
// GET parameters
$param=$_GET['param'];
// command
$prg1="C:\FOLDER1\program.exe ".$param;
// execution
cmd_execution($prg1);
sleep(4);
// file path
$out_pdf="out_folder\\".$name_pdf.".pdf";
// searching time
$limit=30;
$pdf=1;
// file searching
while ($pdf < $limit) {
sleep(1);
$pdf++;
if (file_exists($out_pdf)) {
$pdf=$limit;
}
}
// file output
header('Pragma: anytextexeptno-cache', true);
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="print.pdf"');
header('Content-Length: ' . filesize($out_pdf));
readfile($out_pdf);
die();
|
How can I use FastCGI to avoid apache to lock up more times a day without an a clear reason?
Thanks. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|