简体   繁体   English

php脚本的执行

[英]execution of php script

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. 我知道,当我们在本地主机上执行PHP脚本时,服务器将运行代码并执行所需的处理,并将结果简单地输出到浏览器。 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. 最近,我在阅读有关socket_create函数的信息,该函数创建了服务器和客户端进行通信的连接,但是对此我有疑问。 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. 当我通过输入http://localhost/myprog.php运行程序(使用socket_create)时,... prog命令localhost打开一个套接字。 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? 如果我仍在http:// localhost上运行脚本,这是否意味着脚本将在localhost上运行,而localhost将在另一台服务器上建立套接字? 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. 如上所述,我无法执行此操作,因此必须在其他服务器上运行脚本才能在其上创建套接字。

PHP script is like any other program on machine. PHP脚本与计算机上的任何其他程序一样。 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. 答案是1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM