php服务器没有打开socket google compute

时间:2014-10-01 10:37:39

标签: php sockets google-compute-engine

我正在运行谷歌计算引擎实例。我在计算引擎实例上安装了php5,apache2和mysql。 我已经在防火墙设置中打开了端口“tcp:3000” 然后我把这个代码放在/ var / www /文件夹中打开一个php服务器并做一些自定义的回复。

然而它无法打开并绑定套接字。你能帮忙吗?

这是我的代码:

<?php 
error_reporting(0);
set_time_limit(0);
date_default_timezone_set('Asia/Calcutta');
$address = 'localhost';
$port = 3000;
$max_clients = 10;
$datetime = date("Y-m-d H:i:s");
if(!($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)))
{
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);

    die("Couldn't create socket: [$errorcode] $errormsg \n");
        writeToFile('edmerrorlog.txt', $datetime." :: ".'Couldnt create socket: ['.$errorcode.']'. $errormsg);
}

echo "New Socket created \n";
/*if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) { 
    echo socket_strerror(socket_last_error($sock)); 
        writeToFile('edmerrorlog.txt', $datetime." :: ".socket_strerror(socket_last_error($sock)));
    exit; 
} 
*/

// Bind the source address
if( !socket_bind($sock, $address , $port) )
{
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);

    die("Could not bind socket : [$errorcode] $errormsg \n");
        writeToFile('edmerrorlog.txt', $datetime." :: ".'Could not bind socket : ['.$errorcode.']'. $errormsg);
}

echo "Socket bind OK \n";

if(!socket_listen ($sock , 10))
{
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);

    die("Could not listen on socket : [$errorcode] $errormsg \n");
        writeToFile('edmerrorlog.txt', $datetime." :: ".'Could not listen on socket1 : ['.$errorcode.']'. $errormsg);
}

0 个答案:

没有答案