fsockopen()它是如何工作的?

shi*_*ven 3 php sockets php-socket fsockopen

我正在尝试用PHP开发代码判断软件以进行编程分配.我会尝试在需要套接字编程的java服务器上编译代码.我对PHP中的套接字编程有一些了解.我用谷歌搜索,发现一个代码做了一些类似的工作.但我仍然无法获得事情的要点.它实际上是否有效?手册太技术化,无法获得良好的理解

这是一段代码,根据我的理解,我写了评论:

  $socket = fsockopen($compilerhost, $compilerport); // creates connection it returns the file pointer

if($socket) {  // if it returns a file pointer
fwrite($socket, $_POST['filename']."\n");  //write the filename in the file pointer returned by socket and chagne line

$query = "SELECT time, input, output FROM problems WHERE sl='".$_POST['id']."'"; // select input,output,for the problem

$result = mysql_query($query);

$fields = mysql_fetch_array($result);

fwrite($socket, $fields['time']."\n");  // write the time  in the file pointer returned
Run Code Online (Sandbox Code Playgroud)

我不明白fsockopen是如何工作的?如何在这里使用fwrite?

注意:虽然通过代码我无处找到$ compilerhost,$ compilerport变量.

纠正我的疑虑.谢谢提前和原谅英语不好

pha*_*t0m 8

fsockopen()[PHP.net]允许您通过向您提供可以读取和写入的流的句柄来与服务器通信.

这个"句柄"存储在$socket变量中,它只是fwrite[PHP.net]函数和兄弟姐妹的标识符,因此它知道要写入哪些流等.

当你fwrite()的东西,它就会被发送到服务器.