What's the go equivalent of reading from php standard input?

huangapple go评论84阅读模式
英文:

What's the go equivalent of reading from php standard input?

问题

我正在移植一个用于监听Linux supervisor事件的PHP脚本。

这可能是一个愚蠢的问题,但我不明白这段代码的等价写法是什么:

$fin = fopen ("php://stdin","r");

我需要这个代码,因为当supervisor触发一个事件时,也会启动我的脚本,而我的脚本通过读取php://stdin来监听事件。

英文:

I'm porting a PHP script used to listen linux supervisor's events.

It's probably a stupid question, but I cannot understand what is the equivalent of this

$fin = fopen ("php://stdin","r");

I need this because, when supervisor fires an event, also starts my script, and my script listen events reading from php://stdin

答案1

得分: 3

你的fopen中的只读模式("r")在PHP中对php://处理程序是被忽略的。

根据你想要做什么,你可以使用io.ReadAll(os.Stdin)bufio.NewScanner(os.Stdin)(如果你计划逐行读取)。

英文:

The read-only mode ("r") on your fopen is ignored by PHP for php:// handlers.

Depending on what you want to do, you can io.ReadAll(os.Stdin) or bufio.NewScanner(os.Stdin) (if you plan on line-by-line reading).

huangapple
  • 本文由 发表于 2023年3月14日 00:09:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75724332.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定