2012-10-09 38 views
0

我完全不熟悉php。我有2页让A.php和B.php想要在页面A时运行页面B.为此,我创建了一个套接字连接并且能够运行页面B,但问题是当我发送一个对象数组页面B.page的发送仅在数组的数组和其他值列出的第一个对象是什么 这里是我的一些代码 在a.php只会无法通过POST在套接字连接上发送对象数组php

$arr = array("message" => $pushData, 
    "messageType" => $messageType, 
    "displayGroupID" => $displayGroupID, 
    "db"=>$db); 
$fp1 = $this->JobStartAsync('localhost', 'B.php', $arr); 
$r1 = $this->JobPollAsync($fp1); 

function JobStartAsync($server, $url, $data, $port=80,$conn_timeout=10, $rw_timeout=86400) 
{ 
    $errno = ''; 
    $errstr = ''; 
    $data = http_build_query($data); 

    set_time_limit(0); 

    $fp = fsockopen($server, $port, $errno, $errstr, $conn_timeout); 

    if (!$fp) 
    { 
     echo "$errstr ($errno)<br />\n"; 
     return false; 
    } 

    $out = "POST $url HTTP/1.1\r\n"; 
    $out .= "Host: $server\r\n"; 
    $out .= "Content-type: application/x-www-form-urlencoded\r\n"; 
    $out .= "Content-length: ". strlen($data) ."\r\n"; 
    $out .= "Connection: Close\r\n\r\n"; 
    $out .= "$data"; 
    stream_set_blocking($fp, false); 
    stream_set_timeout($fp, $rw_timeout); 
    fwrite($fp, $out); 
    //fwrite($fp, $data); 
    return $fp; 
} 

function JobPollAsync(&$fp) 
{ 
    if ($fp === false) 
     return false; 

    if (feof($fp)) 
    { 
     fclose($fp); 
     $fp = false; 
     return false; 
    } 

    return fread($fp, 10000); 
} 

IN B.php

fileWrite ($_POST['displayGroupID'],$_POST['message'],$_POST['messageType']); 

它只能得到“消息”,因为它列为数组中的第一个元素

+1

如果你希望有人把钱花在你的问题的时间和帮助你,你应该宁愿花更多的时间来提高你的问题。并且可能会添加一些您正在处理的示例代码。 – Subash

回答

0

看看CURL。这是你需要和其他人使用的。

ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,"http://www.example.com"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 
     "postvar1=value1&postvar2=value2&postvar3=value3"); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$response = curl_exec ($ch); 

curl_close ($ch); 

对于异步变化来看看一个类似的问题之前回答 - How do I make an asynchronous GET request in PHP?

相关问题