Secure Communication Between shell-PHP and Linux Hosts

Source: Internet
Author: User
The desired function is as follows: execute a task on the PHP page of the client, such as creating a site, notifying the backend nc listener in some way, and then executing the relevant script, it is better to create an ftp account and create a directory. But how can I send messages to nc through php? The function to be implemented is as follows:
On the PHP page of the client, execute a task, such as creating a site, notifying the backend nc listener in some way, and then executing related scripts. It is better to create an ftp account and create a directory.

But how can I send messages to nc through php?
Ask for advice!

The following are the php clients:

$fp = fsockopen ("udp://127.0.0.1",40030,$errno,$errstr,30);if(!$fp){    echo "$errstr ($errno) 
";}else{ fwrite($fp,"Hello nc"); echo "Success"; fclose($fp);}

The following is the shell Server:

#!/bin/bashkillall 'nc' >/dev/null 2>&1nc -l -u 40030 | while read Linedo    echo $Linedone

But why not output it?

Reply content:

The following functions are implemented:
On the PHP page of the client, execute a task, such as creating a site, notifying the backend nc listener in some way, and then executing related scripts. It is better to create an ftp account and create a directory.

But how can I send messages to nc through php?
Ask for advice!

The following are the php clients:

$fp = fsockopen ("udp://127.0.0.1",40030,$errno,$errstr,30);if(!$fp){    echo "$errstr ($errno) 
";}else{ fwrite($fp,"Hello nc"); echo "Success"; fclose($fp);}

The following is the shell Server:

#!/bin/bashkillall 'nc' >/dev/null 2>&1nc -l -u 40030 | while read Linedo    echo $Linedone

But why not output it?

Because the Bash read command is Read a line from the standard input and split it into fields.

Therefore, you need to output a line break:fwrite($fp,"Hello nc\n");

In addition, why don't you directly use popen to execute scripts in PHP? Close the nc connection and close it.

Why is the backend using nc? the backend can also be written in PHP, for example, using service frameworks such as workerman?

I don't know what you are doing. However, if you mention security, you must either use UDP or add verification and integrity check on your own. In particular, you actually use nc to process UDP, so the message boundary is gone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.