php – 卷曲 – 反应迟钝

前端之家收集整理的这篇文章主要介绍了php – 卷曲 – 反应迟钝前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从某人那里得到了一个地址和端口号.我正在发送一个名为“tagstream”的东西,并收到一个回复​​,一个zpl标签.

我应该通过套接字连接发送这个标签流来触发“Uni-Box”.我试过用curl做这件事.它有效,但我得到回复大约需要10秒钟.

$ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,'87.213.39.202');
        curl_setopt($ch,CURLOPT_PORT,3032);

        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

        curl_setopt($ch,CURLOPT_POST,0);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$message);

    $zpl = curl_exec($ch);

    curl_close($ch);

这是我从curl_getinfo()得到的:

array:26 [▼
  "url" => "HTTP://87.213.39.202/"
  "content_type" => null
  "http_code" => 0
  "header_size" => 0
  "request_size" => 538
  "filetime" => -1
  "ssl_verify_result" => 0
  "redirect_count" => 0
  "total_time" => 10.327
  "namelookup_time" => 0.0
  "connect_time" => 0.031
  "pretransfer_time" => 0.031
  "size_upload" => 410.0
  "size_download" => 8598.0
  "speed_download" => 832.0
  "speed_upload" => 39.0
  "download_content_length" => -1.0
  "upload_content_length" => 410.0
  "starttransfer_time" => 0.062
  "redirect_time" => 0.0
  "redirect_url" => ""
  "primary_ip" => "87.213.39.202"
  "certinfo" => []
  "primary_port" => 3032
  "local_ip" => "192.168.1.136"
  "local_port" => 49948
]

我还通过这个程序测试了连接:
http://sockettest.sourceforge.net/

当我使用它时,我立即收到回复.

我用xdebug做了一些跟踪:

TRACE START [2015-11-24 10:43:47]
    0.0010     130056   -> {main}() C:\Users\PHPmachine\test.PHP:0
    0.0010     130696     -> curl_init() C:\Users\PHPmachine\test.PHP:4
    0.0010     131600     -> curl_setopt() C:\Users\PHPmachine\test.PHP:5
    0.0010     131576     -> curl_setopt() C:\Users\PHPmachine\test.PHP:6
    0.0010     131576     -> curl_setopt() C:\Users\PHPmachine\test.PHP:7
    0.0010     131576     -> curl_setopt() C:\Users\PHPmachine\test.PHP:9
    0.0010     131576     -> curl_setopt() C:\Users\PHPmachine\test.PHP:11
    0.0010     131544     -> curl_setopt() C:\Users\PHPmachine\test.PHP:12
    0.0010     131512     -> curl_exec() C:\Users\PHPmachine\test.PHP:14
   10.3476     153384     -> curl_getinfo() C:\Users\PHPmachine\test.PHP:15
   10.3476     156232     -> var_dump() C:\Users\PHPmachine\test.PHP:17
   10.3516       8416
TRACE END   [2015-11-24 10:43:58]

我从流程监视器得到了这个:

12:23:34,0427525    PHP.exe 6052    TCP Accept  PHPmachine-PC:8001 -> PHPmachine-PC:52116   SUCCESS Length: 0,mss: 1440,sackopt: 1,tsopt: 0,wsopt: 1,rcvwin: 8192,rcvwinscale: 8,sndwinscale: 8,seqnum: 0,connid: 0
12:23:34,0430792    PHP.exe 6052    TCP Accept  PHPmachine-PC:8001 -> PHPmachine-PC:52117   SUCCESS Length: 0,0481570    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:8001 -> PHPmachine-PC:52116   SUCCESS Length: 1052,0481705    PHP.exe 6052    TCP Receive PHPmachine-PC:8001 -> PHPmachine-PC:52116   SUCCESS Length: 1052,0485330    PHP.exe 6052    CreateFile  C:\Users\PHPmachine SUCCESS Desired Access: Read Data/List Directory,Synchronize,Disposition: Open,Options: Directory,Synchronous IO Non-Alert,Attributes: n/a,ShareMode: Read,Write,Delete,AllocationSize: n/a,OpenResult: Opened
12:23:34,0485752    PHP.exe 6052    QueryDirectory  C:\Users\PHPmachine\test.PHP    SUCCESS Filter: test.PHP,1: test.PHP
12:23:34,0486250    PHP.exe 6052    CloseFile   C:\Users\PHPmachine SUCCESS 
12:23:34,0490208    PHP.exe 6052    CreateFile  C:\Users\PHPmachine SUCCESS Desired Access: Read Attributes,Options: Open Reparse Point,0490670    PHP.exe 6052    QueryNetworkOpenInformationFile C:\Users\PHPmachine SUCCESS CreationTime: 5-11-2014 20:57:57,LastAccessTime: 24-11-2015 11:04:43,LastWriteTime: 24-11-2015 11:04:43,ChangeTime: 24-11-2015 11:04:43,AllocationSize: 1-1-1601 1:00:00,EndOfFile: 1-1-1601 1:00:00,FileAttributes: D
12:23:34,0490802    PHP.exe 6052    CloseFile   C:\Users\PHPmachine SUCCESS 
12:23:34,0491815    PHP.exe 6052    CreateFile  C:\Users\PHPmachine\test.PHP    SUCCESS Desired Access: Generic Read,Options: Synchronous IO Non-Alert,Non-Directory File,Attributes: N,0492591    PHP.exe 6052    QueryInformationVolume  C:\Users\PHPmachine\test.PHP    BUFFER OVERFLOW VolumeCreationTime: 31-10-2014 0:44:17,VolumeSerialNumber: 1C6C-4C1A,SupportsObjects: True,VolumeLabel: Win
12:23:34,0492742    PHP.exe 6052    QueryAllInformationFile C:\Users\PHPmachine\test.PHP    BUFFER OVERFLOW CreationTime: 24-11-2015 10:44:39,LastAccessTime: 24-11-2015 10:44:39,LastWriteTime: 24-11-2015 11:41:30,ChangeTime: 24-11-2015 11:41:30,FileAttributes: A,AllocationSize: 4.096,EndOfFile: 911,NumberOfLinks: 1,DeletePending: False,Directory: False,IndexNumber: 0xb000000023920,EaSize: 0,Access: Generic Read,Position: 0,Mode: Synchronous IO Non-Alert,AlignmentRequirement: Word
12:23:34,0492939    PHP.exe 6052    CreateFileMapping   C:\Users\PHPmachine\test.PHP    FILE LOCKED WITH ONLY READERS   SyncType: SyncTypeCreateSection,PageProtection: 
12:23:34,0493072    PHP.exe 6052    QueryStandardInformationFile    C:\Users\PHPmachine\test.PHP    SUCCESS AllocationSize: 4.096,Directory: False
12:23:34,0493284    PHP.exe 6052    CreateFileMapping   C:\Users\PHPmachine\test.PHP    SUCCESS SyncType: SyncTypeOther
12:23:34,0493580    PHP.exe 6052    QueryStandardInformationFile    C:\Users\PHPmachine\test.PHP    SUCCESS AllocationSize: 4.096,0494642    PHP.exe 6052    CloseFile   C:\Users\PHPmachine\test.PHP    SUCCESS 
12:23:34,0764135    PHP.exe 6052    TCP Connect PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 0,mss: 1460,rcvwin: 65700,sndwinscale: 0,1108071    PHP.exe 6052    TCP Send    PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 626,startime: 112255,endtime: 112256,1115333    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 128,1115718    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 128,3219629    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3220048    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3392041    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3392469    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3400457    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3400661    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3689893    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3690216    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3696465    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1256,3696662    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1256,3766311    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,3766508    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 1460,4040472    PHP.exe 6052    TCP TCPCopy PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 150,4040780    PHP.exe 6052    TCP Receive PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 150,connid: 0
12:23:44,3904869    PHP.exe 6052    CreateFile  C:\Users    SUCCESS Desired Access: Read Data/List Directory,OpenResult: Opened
12:23:44,3905414    PHP.exe 6052    QueryDirectory  C:\Users\PHPmachine SUCCESS Filter: PHPmachine,1: PHPmachine
12:23:44,3906037    PHP.exe 6052    CloseFile   C:\Users    SUCCESS 
12:23:44,3906877    PHP.exe 6052    CreateFile  C:\ SUCCESS Desired Access: Read Data/List Directory,3907428    PHP.exe 6052    QueryDirectory  C:\Users    SUCCESS Filter: Users,1: Users
12:23:44,3908402    PHP.exe 6052    CloseFile   C:\ SUCCESS 
12:23:44,3910462    PHP.exe 6052    CreateFile  C:\Users\PHPmachine SUCCESS Desired Access: Read Attributes,3911072    PHP.exe 6052    QueryNetworkOpenInformationFile C:\Users\PHPmachine SUCCESS CreationTime: 5-11-2014 20:57:57,FileAttributes: D
12:23:44,3911278    PHP.exe 6052    CloseFile   C:\Users\PHPmachine SUCCESS 
12:23:44,3917083    PHP.exe 6052    TCP Send    PHPmachine-PC:8001 -> PHPmachine-PC:52116   SUCCESS Length: 125,startime: 112358,endtime: 112358,3918207    PHP.exe 6052    TCP Send    PHPmachine-PC:8001 -> PHPmachine-PC:52116   SUCCESS Length: 723,3925080    PHP.exe 6052    TCP Disconnect  PHPmachine-PC:8001 -> PHPmachine-PC:52117   SUCCESS Length: 0,3935677    PHP.exe 6052    TCP Disconnect  PHPmachine-PC:8001 -> PHPmachine-PC:52116   SUCCESS Length: 0,4195232    PHP.exe 6052    TCP Disconnect  PHPmachine-PC:52118 -> gateway.gls-netherlands.com:3032 SUCCESS Length: 0,connid: 0
12:23:48,4995571    PHP.exe 6052    Thread Exit     SUCCESS Thread ID: 5964,User Time: 0.0000000,Kernel Time: 0.0000000
12:23:48,4996301    PHP.exe 6052    Thread Exit     SUCCESS Thread ID: 5708,Kernel Time: 0.0000000

我发现了一些有效的东西,但不确定它是不是最好的方法.

这次不使用curl.如果我在没有任何东西可以阅读的情况下使用socket_read,则需要10秒才能获得结果.但是我知道收到的消息应该结束的字符,所以我用它来确定何时停止.

它有效,现在花费的时间更少!

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$result = socket_connect($socket,'87.213.39.202',3032);
socket_write($socket,$message,strlen($message));

$result = '';
$zpl = '';

for($i = 0; $i < 10; $i++) {
    $read = socket_read($socket,2048);
    $zpl = $zpl . $read;
    if(substr($read,-13) == '/////GLS/////') {
        break;
    }
}

socket_close($socket);
> HTTP与http不同 >“http_code”=> 0 – 这表示在请求期间发生错误,甚至没有完成.
原文链接:https://www.f2er.com/php/134069.html

猜你在找的PHP相关文章