@@ -13,21 +13,37 @@ require __DIR__ . '/../include/bootstrap.php';
13
13
$ pm = new ProcessManager ;
14
14
15
15
$ pm ->parentFunc = function () use ($ pm ) {
16
- $ formData = [
17
- 'file1 ' => curl_file_create ('/dev/null ' , 'text/plain ' , 'empty.txt ' ),
18
- 'file2 ' => curl_file_create ('/dev/null ' , 'application/octet-stream ' , ' ' ),
19
- ];
20
-
21
- $ ch = curl_init ();
22
- curl_setopt ($ ch , CURLOPT_URL , "http://127.0.0.1: {$ pm ->getFreePort ()}" );
23
- curl_setopt ($ ch , CURLOPT_HEADER , 0 );
24
- curl_setopt ($ ch , CURLOPT_POST , 1 );
25
- curl_setopt ($ ch , CURLOPT_HTTPHEADER , ['Expect: ' ]);
26
- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ formData );
27
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
28
- $ result = curl_exec ($ ch );
29
- curl_close ($ ch );
16
+ $ boundary = "------------------------d3f990cdce762596 " ;
17
+ $ body = implode ("\r\n" , [
18
+ "-- $ boundary " ,
19
+ 'Content-Disposition: form-data; name="file1"; filename="empty.txt" ' ,
20
+ 'Content-Type: text/plain ' ,
21
+ '' ,
22
+ '' ,
23
+ "-- $ boundary " ,
24
+ 'Content-Disposition: form-data; name="file2"; filename="" ' ,
25
+ 'Content-Type: application/octet-stream ' ,
26
+ '' ,
27
+ '' ,
28
+ "-- $ boundary-- " ,
29
+ '' ,
30
+ ]);
31
+ $ request = implode ("\r\n" , [
32
+ 'POST / HTTP/1.1 ' ,
33
+ "Content-Type: multipart/form-data; boundary= $ boundary " ,
34
+ 'Content-Length: ' . strlen ($ body ),
35
+ '' ,
36
+ '' ,
37
+ $ body ,
38
+ ]);
39
+
40
+ $ sock = stream_socket_client ("tcp://127.0.0.1: {$ pm ->getFreePort ()}" );
41
+ fwrite ($ sock , $ request );
42
+ stream_set_chunk_size ($ sock , 2 * 1024 * 1024 );
43
+ $ response = fread ($ sock , 2 * 1024 * 1024 );
44
+ fclose ($ sock );
30
45
46
+ $ result = ltrim (strstr ($ response , "\r\n\r\n" ));
31
47
echo "$ result \n" ;
32
48
$ pm ->kill ();
33
49
};
0 commit comments