G
G
George2018-06-22 21:01:01
PHP
George, 2018-06-22 21:01:01

Calling an external program on the Apache server using php with a subsequent response?

I woke up and came up with an idea to send and receive information from the LPT port (I send a byte code to the micro controller, it turns on the relays for me: light, electronic locks, etc., as well as read data: Humidity, temperature, Ph-water sensors)

I decided to stir up all this for the greenhouse.

And going like this - there is an old computer on it there is an LPT port, it will serve to "attempt" the implementation of all these plans. And the whole thing will be controlled through the site page.
5b2d34c0aeb80594628387.jpeg
And now I’m sitting thinking how to establish a connection between php honey and an external program / service that also needs to be implemented, I can’t budge because of this, how to implement this bridge.
As an option, use a TCP tunnel, sockets, etc., but it seems to me that this is not the only option, and indeed this option annoys me somehow. In general, I rummaged through the forums on Google, came across fastCGI, started looking for it (I think it’s already close to the goal), I didn’t find anything clear, everything is written everywhere for people who already know the principles of working with PHP and C ++, and I always sawed on the examples of others and different pieces of what there is.
As I think it is necessary to cut a program in C ++, it will accept a request from apache or php directly ... I still can’t imagine how it will work (but not TCP please), process the request at least hello world for a start, then send the response to the web the page from which the request was sent, because in php there seem to be variables that can be passed to the external execution environment, then the question is how to implement this in the external execution environment, receiving these variables, HZ how to file everything, it burns, bombs, I can’t sleep, I look at everything this LPT port, I only dream that all this is already working.
Help cool guys.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nozzy, 2018-06-22
@smallxvile

php.net/manual/en/function.exec.php
php.net/manual/en/function.system.php
php.net/manual/en/function.passthru.php
But I would use Python like:
Flask + https http://github.com/pyserial/pyparallel

V
VadimKholodilo, 2018-06-24
@VadimKholodilo

So is the port serial or parallel? If serial, then the commentator offered you a suitable solution, and if by some miracle parallel, then this:
Write a program in c ++ that can be controlled by command line arguments like this controller.exe /p LPT1 /relay 2
Further in php something like such exec("controller.exe /p LPT1 /relay".$relay); where $relay is the relay that you will turn on. Need help, write https://vk.com/vadimkholodilo

S
Saboteur, 2018-06-23
@saboteur_kiev

CGI allows you to run your program without php at all.
You need to learn html / http and, accordingly, your program should generate an html page for apache.
Write a console program in C/C++/whatever that interacts with the LPT port and can return results in text or html
Learn html forms (how to create a button that calls up a file)
In Apache, set up cgi support - enable cgi module
LoadModule cgi_module modules/mod_cgi.so
Add cgi handler
AddHandler cgi-script .cgi
or
AddHandler cgi-script .exe Enable
cgi in site directory, or even DocumentRoot
Options ExecCGI
try www.mysite.com/myprogram.exe

N
Nikita, 2018-06-23
@vasilek-nik

Or you can go the other way. You know PHP without knowing other languages ​​and you need to work with a serial port. For example, the same Arduino, although connected via USB, is defined as a COM port. There are libraries for PHP to work with it. For example here: https://github.com/lepiaf/serialport
Using this or a similar library, you either get rid of the bridge or write it in PHP. Good luck.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question