fork download
  1. <?php
  2.  
  3. $service_port = getservbyname('http', 'tcp');
  4.  
  5. $address = gethostbyname('i.imgur.com');
  6. $host = "i.imgur.com";
  7. $url = "/e4NumaQ.jpg";
  8.  
  9. $extensions = getMimeCollection();
  10.  
  11.  
  12. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  13. if ($socket === false) {
  14. echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  15. die;
  16. } else {
  17. echo "OK.\n";
  18. }
  19.  
  20.  
  21. $result = socket_connect($socket, $address, $service_port);
  22. if ($result === false) {
  23. echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
  24. die;
  25. } else {
  26. echo "OK.\n";
  27. }
  28.  
  29. $in = "GET $url HTTP/1.1\r\n";
  30. $in .= "Host: $host\r\n";
  31. $in .= "Connection: Close\r\n\r\n";
  32. $out = '';
  33.  
  34. socket_write($socket, $in, strlen($in));
  35.  
  36. $response = '';
  37.  
  38. while ($out = socket_read($socket, 2048)) {
  39. $response .= $out;
  40. }
  41.  
  42. $contentType = preg_match('/Content-Type:\s(.*)[;\r\n]/U', $response, $matches);
  43.  
  44. if(!$contentType) {
  45. $mime = "text/plain";
  46. } else {
  47. $mime = $matches[1];
  48. }
  49.  
  50. if (!isset($extensions[$mime])) {
  51. echo 'unsuported mime type';
  52. socket_close($socket);
  53. die;
  54. }
  55.  
  56. $extension = $extensions[$mime];
  57.  
  58. $response = preg_split('/\r\n\r\n/', $response);
  59. unset($response[0]);
  60. $response = implode('\r\n\r\n', $response);
  61.  
  62.  
  63. $file = fopen(__DIR__ . '/test' . $extension, 'wb');
  64. fwrite($file, $response);
  65. fclose($file);
  66.  
  67.  
  68. echo "Closing socket...";
  69. socket_close($socket);
  70.  
  71. function getMimeCollection() {
  72. return [
  73. 'application/x-authorware-bin' => '.aab',
  74. 'application/x-authorware-map' => '.aam',
  75. 'application/x-authorware-seg' => '.aas',
  76. 'text/vnd.abc' => '.abc',
  77. 'video/animaflex' => '.afl',
  78. 'application/x-aim' => '.aim',
  79. 'text/x-audiosoft-intra' => '.aip',
  80. 'application/x-navi-animation' => '.ani',
  81. 'application/x-nokia-9000-communicator-add-on-software' => '.aos',
  82. 'application/mime' => '.aps',
  83. 'application/arj' => '.arj',
  84. 'image/x-jg' => '.art',
  85. 'text/asp' => '.asp',
  86. 'application/x-mplayer2' => '.asx',
  87. 'video/x-ms-asf-plugin' => '.asx',
  88. 'audio/x-au' => '.au',
  89. 'application/x-troff-msvideo' => '.avi',
  90. 'video/avi' => '.avi',
  91. 'video/msvideo' => '.avi',
  92. 'video/x-msvideo' => '.avi',
  93. 'video/avs-video' => '.avs',
  94. 'application/x-bcpio' => '.bcpio',
  95. 'application/mac-binary' => '.bin',
  96. 'application/macbinary' => '.bin',
  97. 'application/x-binary' => '.bin',
  98. 'application/x-macbinary' => '.bin',
  99. 'image/x-windows-bmp' => '.bmp',
  100. 'application/x-bzip' => '.bz',
  101. 'application/vnd.ms-pki.seccat' => '.cat',
  102. 'application/clariscad' => '.ccad',
  103. 'application/x-cocoa' => '.cco',
  104. 'application/cdf' => '.cdf',
  105. 'application/x-cdf' => '.cdf',
  106. 'application/java' => '.class',
  107. 'application/java-byte-code' => '.class',
  108. 'application/x-java-class' => '.class',
  109. 'application/x-cpio' => '.cpio',
  110. 'application/mac-compactpro' => '.cpt',
  111. 'application/x-compactpro' => '.cpt',
  112. 'application/x-cpt' => '.cpt',
  113. 'application/pkcs-crl' => '.crl',
  114. 'application/pkix-crl' => '.crl',
  115. 'application/x-x509-user-cert' => '.crt',
  116. 'application/x-csh' => '.csh',
  117. 'text/x-script.csh' => '.csh',
  118. 'application/x-pointplus' => '.css',
  119. 'text/css' => '.css',
  120. 'application/x-deepv' => '.deepv',
  121. 'video/dl' => '.dl',
  122. 'video/x-dl' => '.dl',
  123. 'application/commonground' => '.dp',
  124. 'application/drafting' => '.drw',
  125. 'application/x-dvi' => '.dvi',
  126. 'drawing/x-dwf (old)' => '.dwf',
  127. 'model/vnd.dwf' => '.dwf',
  128. 'application/acad' => '.dwg',
  129. 'application/dxf' => '.dxf',
  130. 'text/x-script.elisp' => '.el',
  131. 'application/x-bytecode.elisp (compiled elisp)' => '.elc',
  132. 'application/x-elc' => '.elc',
  133. 'application/x-esrehber' => '.es',
  134. 'text/x-setext' => '.etx',
  135. 'application/envoy' => '.evy',
  136. 'application/vnd.fdf' => '.fdf',
  137. 'application/fractals' => '.fif',
  138. 'image/fif' => '.fif',
  139. 'video/fli' => '.fli',
  140. 'video/x-fli' => '.fli',
  141. 'text/vnd.fmi.flexstor' => '.flx',
  142. 'video/x-atomic3d-feature' => '.fmf',
  143. 'image/vnd.fpx' => '.fpx',
  144. 'image/vnd.net-fpx' => '.fpx',
  145. 'application/freeloader' => '.frl',
  146. 'image/g3fax' => '.g3',
  147. 'image/gif' => '.gif',
  148. 'video/gl' => '.gl',
  149. 'video/x-gl' => '.gl',
  150. 'application/x-gsp' => '.gsp',
  151. 'application/x-gss' => '.gss',
  152. 'application/x-gtar' => '.gtar',
  153. 'multipart/x-gzip' => '.gzip',
  154. 'application/x-hdf' => '.hdf',
  155. 'text/x-script' => '.hlb',
  156. 'application/hlp' => '.hlp',
  157. 'application/x-winhelp' => '.hlp',
  158. 'application/binhex' => '.hqx',
  159. 'application/binhex4' => '.hqx',
  160. 'application/mac-binhex' => '.hqx',
  161. 'application/mac-binhex40' => '.hqx',
  162. 'application/x-binhex40' => '.hqx',
  163. 'application/x-mac-binhex40' => '.hqx',
  164. 'application/hta' => '.hta',
  165. 'text/x-component' => '.htc',
  166. 'text/webviewhtml' => '.htt',
  167. 'x-conference/x-cooltalk' => '.ice ',
  168. 'image/x-icon' => '.ico',
  169. 'application/x-ima' => '.ima',
  170. 'application/x-httpd-imap' => '.imap',
  171. 'application/inf' => '.inf ',
  172. 'application/x-internett-signup' => '.ins',
  173. 'application/x-ip2' => '.ip ',
  174. 'video/x-isvideo' => '.isu',
  175. 'audio/it' => '.it',
  176. 'application/x-inventor' => '.iv',
  177. 'i-world/i-vrml' => '.ivr',
  178. 'application/x-livescreen' => '.ivy',
  179. 'audio/x-jam' => '.jam ',
  180. 'application/x-java-commerce' => '.jcm ',
  181. 'image/x-jps' => '.jps',
  182. 'application/x-javascript' => '.js ',
  183. 'image/jutvision' => '.jut',
  184. 'music/x-karaoke' => '.kar',
  185. 'application/x-ksh' => '.ksh',
  186. 'text/x-script.ksh' => '.ksh',
  187. 'audio/x-liveaudio' => '.lam',
  188. 'application/lha' => '.lha',
  189. 'application/x-lha' => '.lha',
  190. 'application/x-lisp' => '.lsp ',
  191. 'text/x-script.lisp' => '.lsp ',
  192. 'text/x-la-asf' => '.lsx',
  193. 'application/x-lzh' => '.lzh',
  194. 'application/lzx' => '.lzx',
  195. 'application/x-lzx' => '.lzx',
  196. 'text/x-m' => '.m',
  197. 'audio/x-mpequrl' => '.m3u ',
  198. 'application/x-troff-man' => '.man',
  199. 'application/x-navimap' => '.map',
  200. 'application/mbedlet' => '.mbd',
  201. 'application/x-magic-cap-package-1.0' => '.mc$',
  202. 'application/mcad' => '.mcd',
  203. 'application/x-mathcad' => '.mcd',
  204. 'image/vasa' => '.mcf',
  205. 'text/mcf' => '.mcf',
  206. 'application/netmc' => '.mcp',
  207. 'application/x-troff-me' => '.me ',
  208. 'application/x-frame' => '.mif',
  209. 'application/x-mif' => '.mif',
  210. 'www/mime' => '.mime ',
  211. 'audio/x-vnd.audioexplosion.mjuicemediafile' => '.mjf',
  212. 'video/x-motion-jpeg' => '.mjpg ',
  213. 'application/x-meme' => '.mm',
  214. 'audio/mod' => '.mod',
  215. 'audio/x-mod' => '.mod',
  216. 'audio/x-mpeg' => '.mp2',
  217. 'video/x-mpeq2a' => '.mp2',
  218. 'audio/mpeg3' => '.mp3',
  219. 'audio/x-mpeg-3' => '.mp3',
  220. 'application/vnd.ms-project' => '.mpp',
  221. 'application/marc' => '.mrc',
  222. 'application/x-troff-ms' => '.ms',
  223. 'application/x-vnd.audioexplosion.mzz' => '.mzz',
  224. 'application/vnd.nokia.configuration-message' => '.ncm',
  225. 'application/x-mix-transfer' => '.nix',
  226. 'application/x-conference' => '.nsc',
  227. 'application/x-navidoc' => '.nvd',
  228. 'application/oda' => '.oda',
  229. 'application/x-omc' => '.omc',
  230. 'application/x-omcdatamaker' => '.omcd',
  231. 'application/x-omcregerator' => '.omcr',
  232. 'text/x-pascal' => '.p',
  233. 'application/pkcs10' => '.p10',
  234. 'application/x-pkcs10' => '.p10',
  235. 'application/pkcs-12' => '.p12',
  236. 'application/x-pkcs12' => '.p12',
  237. 'application/x-pkcs7-signature' => '.p7a',
  238. 'application/x-pkcs7-certreqresp' => '.p7r',
  239. 'application/pkcs7-signature' => '.p7s',
  240. 'text/pascal' => '.pas',
  241. 'image/x-portable-bitmap' => '.pbm ',
  242. 'application/vnd.hp-pcl' => '.pcl',
  243. 'application/x-pcl' => '.pcl',
  244. 'image/x-pict' => '.pct',
  245. 'image/x-pcx' => '.pcx',
  246. 'application/pdf' => '.pdf',
  247. 'audio/make.my.funk' => '.pfunk',
  248. 'image/x-portable-graymap' => '.pgm',
  249. 'image/x-portable-greymap' => '.pgm',
  250. 'application/x-newton-compatible-pkg' => '.pkg',
  251. 'application/vnd.ms-pki.pko' => '.pko',
  252. 'text/x-script.perl' => '.pl',
  253. 'application/x-pixclscript' => '.plx',
  254. 'text/x-script.perl-module' => '.pm',
  255. 'application/x-portable-anymap' => '.pnm',
  256. 'image/x-portable-anymap' => '.pnm',
  257. 'model/x-pov' => '.pov',
  258. 'image/x-portable-pixmap' => '.ppm',
  259. 'application/powerpoint' => '.ppt',
  260. 'application/x-mspowerpoint' => '.ppt',
  261. 'application/x-freelance' => '.pre',
  262. 'paleovu/x-pv' => '.pvu',
  263. 'text/x-script.phyton' => '.py ',
  264. 'applicaiton/x-bytecode.python' => '.pyc ',
  265. 'audio/vnd.qcelp' => '.qcp ',
  266. 'video/x-qtc' => '.qtc',
  267. 'audio/x-realaudio' => '.ra',
  268. 'application/x-cmu-raster' => '.ras',
  269. 'image/x-cmu-raster' => '.ras',
  270. 'text/x-script.rexx' => '.rexx ',
  271. 'image/vnd.rn-realflash' => '.rf',
  272. 'image/x-rgb' => '.rgb ',
  273. 'application/vnd.rn-realmedia' => '.rm',
  274. 'audio/mid' => '.rmi',
  275. 'application/ringing-tones' => '.rng',
  276. 'application/vnd.nokia.ringing-tone' => '.rng',
  277. 'application/vnd.rn-realplayer' => '.rnx ',
  278. 'image/vnd.rn-realpix' => '.rp ',
  279. 'text/vnd.rn-realtext' => '.rt',
  280. 'application/x-rtf' => '.rtf',
  281. 'video/vnd.rn-realvideo' => '.rv',
  282. 'audio/s3m' => '.s3m ',
  283. 'application/x-lotusscreencam' => '.scm',
  284. 'text/x-script.guile' => '.scm',
  285. 'text/x-script.scheme' => '.scm',
  286. 'video/x-scm' => '.scm',
  287. 'application/sdp' => '.sdp ',
  288. 'application/x-sdp' => '.sdp ',
  289. 'application/sounder' => '.sdr',
  290. 'application/sea' => '.sea',
  291. 'application/x-sea' => '.sea',
  292. 'application/set' => '.set',
  293. 'application/x-sh' => '.sh',
  294. 'text/x-script.sh' => '.sh',
  295. 'audio/x-psid' => '.sid',
  296. 'application/x-sit' => '.sit',
  297. 'application/x-stuffit' => '.sit',
  298. 'application/x-seelogo' => '.sl ',
  299. 'audio/x-adpcm' => '.snd',
  300. 'application/solids' => '.sol',
  301. 'application/x-pkcs7-certificates' => '.spc ',
  302. 'application/futuresplash' => '.spl',
  303. 'application/streamingmedia' => '.ssm ',
  304. 'application/vnd.ms-pki.certstore' => '.sst',
  305. 'application/sla' => '.stl',
  306. 'application/vnd.ms-pki.stl' => '.stl',
  307. 'application/x-navistyle' => '.stl',
  308. 'application/x-sv4cpio' => '.sv4cpio',
  309. 'application/x-sv4crc' => '.sv4crc',
  310. 'x-world/x-svr' => '.svr',
  311. 'application/x-shockwave-flash' => '.swf',
  312. 'application/x-tar' => '.tar',
  313. 'application/toolbook' => '.tbk',
  314. 'application/x-tcl' => '.tcl',
  315. 'text/x-script.tcl' => '.tcl',
  316. 'text/x-script.tcsh' => '.tcsh',
  317. 'application/x-tex' => '.tex',
  318. 'application/plain' => '.text',
  319. 'application/gnutar' => '.tgz',
  320. 'audio/tsp-audio' => '.tsi',
  321. 'application/dsptype' => '.tsp',
  322. 'audio/tsplayer' => '.tsp',
  323. 'text/tab-separated-values' => '.tsv',
  324. 'text/x-uil' => '.uil',
  325. 'application/i-deas' => '.unv',
  326. 'application/x-ustar' => '.ustar',
  327. 'multipart/x-ustar' => '.ustar',
  328. 'application/x-cdlink' => '.vcd',
  329. 'text/x-vcalendar' => '.vcs',
  330. 'application/vda' => '.vda',
  331. 'video/vdo' => '.vdo',
  332. 'application/groupwise' => '.vew ',
  333. 'application/vocaltec-media-desc' => '.vmd ',
  334. 'application/vocaltec-media-file' => '.vmf',
  335. 'audio/voc' => '.voc',
  336. 'audio/x-voc' => '.voc',
  337. 'video/vosaic' => '.vos',
  338. 'audio/voxware' => '.vox',
  339. 'audio/x-twinvq' => '.vqf',
  340. 'application/x-vrml' => '.vrml',
  341. 'x-world/x-vrt' => '.vrt',
  342. 'application/wordperfect6.1' => '.w61',
  343. 'audio/wav' => '.wav',
  344. 'audio/x-wav' => '.wav',
  345. 'application/x-qpro' => '.wb1',
  346. 'image/vnd.wap.wbmp' => '.wbmp',
  347. 'application/vnd.xara' => '.web',
  348. 'application/x-123' => '.wk1',
  349. 'windows/metafile' => '.wmf',
  350. 'text/vnd.wap.wml' => '.wml',
  351. 'application/vnd.wap.wmlc' => '.wmlc ',
  352. 'text/vnd.wap.wmlscript' => '.wmls',
  353. 'application/vnd.wap.wmlscriptc' => '.wmlsc ',
  354. 'application/x-wpwin' => '.wpd',
  355. 'application/x-lotus' => '.wq1',
  356. 'application/mswrite' => '.wri',
  357. 'application/x-wri' => '.wri',
  358. 'text/scriplet' => '.wsc',
  359. 'application/x-wintalk' => '.wtk ',
  360. 'image/x-xbitmap' => '.xbm',
  361. 'image/x-xbm' => '.xbm',
  362. 'image/xbm' => '.xbm',
  363. 'video/x-amt-demorun' => '.xdr',
  364. 'xgl/drawing' => '.xgz',
  365. 'image/vnd.xiff' => '.xif',
  366. 'audio/xm' => '.xm',
  367. 'application/xml' => '.xml',
  368. 'text/xml' => '.xml',
  369. 'xgl/movie' => '.xmz',
  370. 'application/x-vnd.ls-xpix' => '.xpix',
  371. 'image/xpm' => '.xpm',
  372. 'video/x-amt-showrun' => '.xsr',
  373. 'image/x-xwd' => '.xwd',
  374. 'image/x-xwindowdump' => '.xwd',
  375. 'application/x-compress' => '.z',
  376. 'application/x-zip-compressed' => '.zip',
  377. 'application/zip' => '.zip',
  378. 'multipart/x-zip' => '.zip',
  379. 'text/x-script.zsh' => '.zsh',
  380. 'text/html' => '.html',
  381. 'image/bmp' => '.bmp',
  382. 'text/plain' => '.txt',
  383. 'image/jpeg' => '.jpg',
  384. 'image/pjpeg' => '.jpg',
  385. 'image/png' => '.png',
  386. ];
  387. }
Success #stdin #stdout #stderr 0.01s 52568KB
stdin
Standard input is empty
stdout
OK.
socket_connect() failed.
Reason: () Host name lookup failure
stderr
PHP Warning:  socket_connect(): Host lookup failed [-10002]: Host name lookup failure in /home/oD0V5O/prog.php on line 22