执行php脚本

发布于 2024-12-21 21:20:22 字数 632 浏览 3 评论 0原文

我知道当我们在本地主机上执行 PHP 脚本时,服务器会运行代码并进行所需的处理,然后将结果输出到浏览器。最近,我正在阅读有关 socket_create 函数,该函数为服务器创建连接并客户沟通,但我对此有疑问。以下是我的想法,如有错误请指正。

当我通过输入 http://localhost/myprog.php 运行我的程序(使用 socket_create)时... prog 命令 localhost 打开一个套接字。这没问题,但是如果我想在其他服务器上创建套接字怎么办? (下面有两个选项,请告诉我哪个是正确的)

  1. 如果我仍然在 http://localhost 上运行脚本,这是否意味着 脚本将在本地主机上运行,​​本地主机将在本地主机上创建一个套接字 其他服务器?如果我想向其他服务器提供一些输入 输入将通过 localhost 传递。

  2. 我不能按照上面所说的那样做,我必须在其他设备上运行我的脚本 服务器上创建一个套接字。

I know that when we execute a PHP script on localhost, the server runs the code and does the required processing and simply outputs the result to the browser. Recently, I was reading about socket_create function which creates a connection for server and client to communicate, but I have a doubt regarding it. Below is what I think, please correct me if i am wrong.

When I run my program (which uses socket_create) by typing http://localhost/myprog.php... The prog commands localhost to make a open a socket. This is ok, but what if I want to create socket on some other server? (Below are two options, please tell me which is correct)

  1. If I still run the script on http://localhost does that mean the
    script will run on localhost and localhost will make a socket on the
    other server? And if I want to give some input to the other server
    the input will pass through localhost.

  2. I can't do it as told above, I would have to run my script on other
    server to create a socket on it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2024-12-28 21:20:22

PHP 脚本就像机器上的任何其他程序一样。如果您访问本地主机上的脚本,并且该脚本创建套接字,然后本地计算机上的脚本连接到其他服务器,检索输出,将其传递回脚本。如果您访问某个远程主机,则脚本将在此远程主机上执行 - 这是唯一的区别。
所以答案是1。

PHP script is like any other program on machine. If you access script which is on localhost, and this script creates socket then script on your local machine connect to the other server, retrieves output, pass it back to script. If you access some remote host, then script is executed on this remote host - that's only difference.
So the answer is 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文