Windows Prompt read and send text by COM port - php

I need a program to send and receive some text by a COM port. I would like to launch this by a exec command (command line).
I tried to view if Hyperterminal or putty can be used by command line but i can not find a solution.
This would be a workaround to send and receive text by a PHP webserver, I'm going to use the php exec function to run it.

I published two tiny command line applications called SerialSend and ComPrinter on my blog, which send and receive text via serial port. I'm not sure if they'll do exactly what you need since one only sends and the other only receives, but maybe you can get them to do what you want. They're completely free, you can download binary or sourcecode (they're really easy to compile), and they're both really easy to use.
Here are the links:
SerialSend web page
ComPrinter web page

Related

How to get network traffic info and display it in PHP

i have server ubuntu . I want to show network traffic upload & download in php .
A command is in the terminal for monitoring traffic: enter link description here
How can I use command nload -mon php.
Like this :
i have no idia about it
The simplest solution is:
to call this function in PHP file via exec().
to parse the output from this function and prepare the markup to present those values (total input/output) on the page.
Better solutions depend on how often this info should be retrieved and how pretty it should be rendered in the browser.
It compiles php to apache and apache simply does not access network uses. There are several ways for this;
1-) shell_exec;
In ubuntu you can prepare a console command that will output the network data as json, then you can run this console command in ubuntu using shell_exec in php.
2-) third part programming;
For example, you can develop scripts on platforms such as python, node js, etc. and access network usage. Again, with the software you have developed, you can instantly print the network usages to the database. In another option, you can access network information with software such as phton and show them on socket, and you can get data from php with socket. Finally, you can develop an api for this on pyhton.

How to perform serial communication using PHP on IIS on Windows 10

I'm looking for a way to read/write a PC's serial com port using PHP/IIS on Windows 10. I've experimented for a few days now, but every attempt failed.
I tried to use php_dio.php, only to find out this dll misses some essential implementation on Windows. Through StackOverflow I also read that it would impossible for PHP on Windows to do this.
I can use Powershell on Windows to perform the tasks I want using scripts, but I'm not able to gets it output. Also, I fail to start this from PHP using exec or shell_exec.
So, at the moment, I'm stuck. My goal is to create a PHP-file which is able to receive requests from the web. That request would than be translated into a command which I would send to a device which is connected on my com-port. The response on the com-port would then be sent back to the server which did the request. It's just simple serial I/O, like 9600 bd, No parity etc. The setup works, but like I said, every attempt to use PHP to access the com port fails.
Is there a way?
Suggestions are appreciated.
Thanks.
Tried php_dio, exec, shell_exec

Testing my php scripts and forms

I have two html forms and two php scripts. The first one is a form which is supposed to submit a users email to a .txt file, and the other is a Stripe payment form which uses php code to charge the customer.
Now my problem is that there are some issues with the two php scripts, that I can't figure out how to fix, because I am not really sure how to test the scripts. Normally when testing the html scripts I would just open the html files in my browser, but that doesn't work on my php scripts as the site just shows what is written in the scripts when called/submitted.
So my question is how do I test my scripts, without having to use a hosting account and can I even test it like this?
You need to run a web server on your local computer to test it out. I would suggest looking into something called Vagrant, which allows you to fairly easily create virtual machines on your computer in which you can install anything you like without fear of messing up anything else. If you go here you can even find a "box" to create a virtual machine that already has apache and php installed.
Depending on your version of PHP there's a webserver builtin right into PHP:
http://php.net/manual/en/features.commandline.webserver.php
You probably have to install a web server locally with php enabled. Since php is a server side language it needs a server to run on, in order to send you back the html, after execution. If you need to see the result on a browser.
http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29.
Or run your script from terminal (you must have php installed) if you don't need to see the result in the browser and just want to run your script.
$ php myscript.php

Get info from my router VIA SSH CLI from a php page

All,
I'm fairly new to php (simple forms and hello world stuff)
I'm trying to create a page that when loaded will go out grab some text information from a SSH session on my router parse it out and display it
The general idea would be
connect to (ip address, port)
send line (loginuser + Password)
send line (su to root + password)
send line (command)
receive text from command (string X)
parse x and display stats as html on page
I've seen a few tutorials on how to install libraries from ubuntu but my host is godaddy so i wont have access to install anything in that manner (i only have simple ftp access)
I'm looking for a simple simple simple ssh client and hopefully a small example on how to use it (send commands and retrieve text)
Thanks if you can help
Ok, just for learning purposes, you can shell_exec on your box to connect to remote host with ssh, run a command and return response, evaluate and make some nice stats:
shell_exec("ssh user#yourhost.com run_your_command");
http://www.php.net/manual/en/function.shell-exec.php
I would use phpseclib (http://phpseclib.sourceforge.net/), a pure PHP SSH implementation, or if is available on your host use SSH2 extension. http://www.php.net/manual/en/function.ssh2-exec.php
PHP is not the right tool in my opinion, you can achieve better results with expect and some bash stuff.
expect is a good tool for command line activities. Try to have a look

The horrors of working with executables on windows

I run an executable called Test.exe via exec which in turns runs Outlook.
I am able to run the Test.exe fine but I get the error:
Rejected Safe Mode action : Microsoft Office Outlook. in the windows event viewer.
If I run Test.exe myself via DOS it works fine and no errors. So its something to do with how PHP is running this exectuable. I've enabled apache to run as an admin account but the same thing happens.
What else should I be doing so that Apache can run the executable without any problems?
It works from the command line but not from the Apache process. Not surprisingly because Apache probably runs as a service, with a system account (Non-Desktop interactive).
If you reconfigure the service to run as a user with the right to logon locally and mark the service to be allowed 'Interaction with Desktop', I expect you could do this.
However, I'm at a total loss why anyone, at all, would want to start Outlook from a webserver application....
Sehe is right (but for some reason I cannot comment to his post, whatever...). Usually, you should access MS Office facilities via external code using specific OLE interfaces. You never use CreateProcess to start Outlook or Word from your program, it would be pointless because how can you control it after launching it?
I suggest you to check if you really need this, and if there's a more clean way to do it. You can try to create an external C#/VB.NET executable that performs all the automation you may need to do with Microsoft Outlook, indeed.
What is the actual scenario?
And, I don't like to correct people but if I don't, someone else will in the future and it'll be annoying. Don't say "via DOS" when you use a prompt under Windows. :D
i too am perplexed by would anyone would want to do this.
If you REALLY wanted to do this i guess you could run it as "start test.exe" or write a batch file that would run it. basically anything that would cause a different process to be the one actually launching the app.

Categories