English 中文(简体)
how do you fix the clients outgoing port number using php?
原标题:

I m using php (the sockets extension) to handle sending and receiving xml files. I d like to be able to fix the outgoing clients port number as the server has a set amount of incoming connections. I find that each time the php script is run it creates a new port number. The client side script I have so far is this:-



send_message( 192.9.2.50 , 10220 ,$xmlCmd->asXML());

function send_message($ipaddr, $port, $msg)
{
  $fp = stream_socket_client("tcp://".$ipaddr.":".$port, $errno, $errstr);

  if (!$fp)
  {
    echo "ERR : $errno - $errstr";
  }
  else
  {
    fwrite($fp,$msg);
    $response = fread($fp,1024);
    // Make a SimpleXML object from the response
    $xml = new SimpleXMLElement($response);

    echo $xml->Channel->Air->Index;

    fclose($fp);
  }
}


Update:

I ll try using file_get_contents again but the xml only seemed to pass from client to server ie no reply. Could anyone help me with the stream_context_create options, I need to combine these two but can t seem to get it right. Code:-


    $opts = array( http  => 
      array(  method   =>  POST ,
         header   =>  Content-type: text/xml; ,
         content  => $msg)                             
    );
//combine with these options

$opts = array( socket =>array( bindto =>"192.9.2.60:2800"));
问题回答

Do a basic checklist on the network level:

  • Is 192.9.2.60 an IP on an actual interface on the server?
  • Are there any routing or firewall rules that affect it? In Linux try ``ip route get x.x.x.x src 192.9.2.60 and iptables -L
  • Are there any other settings (eg SELinux) that interfere with PHP from binding to high ports?
  • Run a sniffer and see what the server response actually says




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签