Guest User

Untitled

a guest
Jun 18th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.26 KB | None | 0 0
  1. make_request('http://www.externalsite.com/script1.php?variable=45'); //example usage
  2.  
  3. $output = make_request('http://www.externalsite.com/script2.php?variable=45');
  4. echo $output; //string output
  5.  
  6. $output = file_get_contents('http://www.example.com/');
  7. echo $output;
  8.  
  9. function curl_post_async($url, $params)
  10. {
  11. foreach ($params as $key => &$val) {
  12. if (is_array($val)) $val = implode(',', $val);
  13. $post_params[] = $key.'='.urlencode($val);
  14. }
  15. $post_string = implode('&', $post_params);
  16.  
  17. $parts=parse_url($url);
  18.  
  19. $fp = fsockopen($parts['host'],
  20. isset($parts['port'])?$parts['port']:80,
  21. $errno, $errstr, 30);
  22.  
  23. $out = "POST ".$parts['path']." HTTP/1.1rn";
  24. $out.= "Host: ".$parts['host']."rn";
  25. $out.= "Content-Type: application/x-www-form-urlencodedrn";
  26. $out.= "Content-Length: ".strlen($post_string)."rn";
  27. $out.= "Connection: Closernrn";
  28. if (isset($post_string)) $out.= $post_string;
  29.  
  30. fwrite($fp, $out);
  31. fclose($fp);
  32. }
  33.  
  34. // $type must equal 'GET' or 'POST'
  35. function curl_request_async($url, $params, $type='POST')
  36. {
  37. foreach ($params as $key => &$val) {
  38. if (is_array($val)) $val = implode(',', $val);
  39. $post_params[] = $key.'='.urlencode($val);
  40. }
  41. $post_string = implode('&', $post_params);
  42.  
  43. $parts=parse_url($url);
  44.  
  45. $fp = fsockopen($parts['host'],
  46. isset($parts['port'])?$parts['port']:80,
  47. $errno, $errstr, 30);
  48.  
  49. // Data goes in the path for a GET request
  50. if('GET' == $type) $parts['path'] .= '?'.$post_string;
  51.  
  52. $out = "$type ".$parts['path']." HTTP/1.1rn";
  53. $out.= "Host: ".$parts['host']."rn";
  54. $out.= "Content-Type: application/x-www-form-urlencodedrn";
  55. $out.= "Content-Length: ".strlen($post_string)."rn";
  56. $out.= "Connection: Closernrn";
  57. // Data goes in the request body for a POST request
  58. if ('POST' == $type && isset($post_string)) $out.= $post_string;
  59.  
  60. fwrite($fp, $out);
  61. fclose($fp);
  62. }
  63.  
  64. <?php
  65. $request = new cURLRequest('http://www.externalsite.com/script2.php?variable=45');
  66. $request->getOptions()
  67. ->set(CURLOPT_TIMEOUT, 5)
  68. ->set(CURLOPT_RETURNTRANSFER, true);
  69.  
  70. // add callback when the request will be completed
  71. $request->addListener('complete', function (cURLEvent $event) {
  72. $response = $event->response;
  73. $content = $response->getContent();
  74. echo $content;
  75. });
  76.  
  77. while ($request->socketPerform()) {
  78. // do anything else when the request is processed
  79. }
  80.  
  81. function make_request($url, $waitResult=true){
  82. $cmi = curl_multi_init();
  83.  
  84. $curl = curl_init();
  85. curl_setopt($curl, CURLOPT_URL, $url);
  86. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  87.  
  88. curl_multi_add_handle($cmi, $curl);
  89.  
  90. $running = null;
  91. do {
  92. curl_multi_exec($cmi, $running);
  93. sleep(.1);
  94. if(!$waitResult)
  95. break;
  96. } while ($running > 0);
  97. curl_multi_remove_handle($cmi, $curl);
  98. if($waitResult){
  99. $curlInfos = curl_getinfo($curl);
  100. if((int) $curlInfos['http_code'] == 200){
  101. curl_multi_close($cmi);
  102. return curl_multi_getcontent($curl);
  103. }
  104. }
  105. curl_multi_close($cmi);
  106. }
  107.  
  108. <?
  109. $urls = array_fill(0, 100, 'http://google.com/blank.html');
  110.  
  111. function execinbackground($cmd) {
  112. if (substr(php_uname(), 0, 7) == "Windows"){
  113. pclose(popen("start /B ". $cmd, "r"));
  114. }
  115. else {
  116. exec($cmd . " > /dev/null &");
  117. }
  118. }
  119. fwite(fopen("urls.txt","w"),implode("n",$urls);
  120. execinbackground("nodejs urlscript.js urls.txt");
  121. // { do your work while get requests being executed.. }
  122. ?>
  123.  
  124. var https = require('https');
  125. var url = require('url');
  126. var http = require('http');
  127. var fs = require('fs');
  128. var dosya = process.argv[2];
  129. var logdosya = 'log.txt';
  130. var count=0;
  131. http.globalAgent.maxSockets = 300;
  132. https.globalAgent.maxSockets = 300;
  133.  
  134. setTimeout(timeout,100000); // maximum execution time (in ms)
  135.  
  136. function trim(string) {
  137. return string.replace(/^s*|s*$/g, '')
  138. }
  139.  
  140. fs.readFile(process.argv[2], 'utf8', function (err, data) {
  141. if (err) {
  142. throw err;
  143. }
  144. parcala(data);
  145. });
  146.  
  147. function parcala(data) {
  148. var data = data.split("n");
  149. count=''+data.length+'-'+data[1];
  150. data.forEach(function (d) {
  151. req(trim(d));
  152. });
  153. /*
  154. fs.unlink(dosya, function d() {
  155. console.log('<%s> file deleted', dosya);
  156. });
  157. */
  158. }
  159.  
  160.  
  161. function req(link) {
  162. var linkinfo = url.parse(link);
  163. if (linkinfo.protocol == 'https:') {
  164. var options = {
  165. host: linkinfo.host,
  166. port: 443,
  167. path: linkinfo.path,
  168. method: 'GET'
  169. };
  170. https.get(options, function(res) {res.on('data', function(d) {});}).on('error', function(e) {console.error(e);});
  171. } else {
  172. var options = {
  173. host: linkinfo.host,
  174. port: 80,
  175. path: linkinfo.path,
  176. method: 'GET'
  177. };
  178. http.get(options, function(res) {res.on('data', function(d) {});}).on('error', function(e) {console.error(e);});
  179. }
  180. }
  181.  
  182.  
  183. process.on('exit', onExit);
  184.  
  185. function onExit() {
  186. log();
  187. }
  188.  
  189. function timeout()
  190. {
  191. console.log("i am too far gone");process.exit();
  192. }
  193.  
  194. function log()
  195. {
  196. var fd = fs.openSync(logdosya, 'a+');
  197. fs.writeSync(fd, dosya + '-'+count+'n');
  198. fs.closeSync(fd);
  199. }
  200.  
  201. function _async_http_post($url, $json_string) {
  202. $run = "curl -X POST -H 'Content-Type: application/json'";
  203. $run.= " -d '" .$json_string. "' " . "'" . $url . "'";
  204. $run.= " > /dev/null 2>&1 &";
  205. exec($run, $output, $exit);
  206. return $exit == 0;
  207. }
  208.  
  209. // Build the multi-curl handle, adding both $ch
  210. $mh = curl_multi_init();
  211.  
  212. // Build the individual requests, but do not execute them
  213. $chs = [];
  214. $chs['ID0001'] = curl_init('http://webservice.example.com/?method=say&word=Hello');
  215. $chs['ID0002'] = curl_init('http://webservice.example.com/?method=say&word=World');
  216. // $chs[] = ...
  217. foreach ($chs as $ch) {
  218. curl_setopt_array($ch, [
  219. CURLOPT_RETURNTRANSFER => true, // Return requested content as string
  220. CURLOPT_HEADER => false, // Don't save returned headers to result
  221. CURLOPT_CONNECTTIMEOUT => 10, // Max seconds wait for connect
  222. CURLOPT_TIMEOUT => 20, // Max seconds on all of request
  223. CURLOPT_USERAGENT => 'Robot YetAnotherRobo 1.0',
  224. ]);
  225.  
  226. // Well, with a little more of code you can use POST queries too
  227. // Also, useful options above can be CURLOPT_SSL_VERIFYHOST => 0
  228. // and CURLOPT_SSL_VERIFYPEER => false ...
  229.  
  230. // Add every $ch to the multi-curl handle
  231. curl_multi_add_handle($mh, $ch);
  232. }
  233.  
  234. // Execute all of queries simultaneously, and continue when ALL OF THEM are complete
  235. $running = null;
  236. do {
  237. curl_multi_exec($mh, $running);
  238. } while ($running);
  239.  
  240. // Close the handles
  241. foreach ($chs as $ch) {
  242. curl_multi_remove_handle($mh, $ch);
  243. }
  244. curl_multi_close($mh);
  245.  
  246. // All of our requests are done, we can now access the results
  247. // With a help of ids we can understand what response was given
  248. // on every concrete our request
  249. $responses = [];
  250. foreach ($chs as $id => $ch) {
  251. $responses[$id] = curl_multi_getcontent($ch);
  252. curl_close($ch);
  253. }
  254. unset($chs); // Finita, no more need any curls :-)
  255.  
  256. print_r($responses); // output results
  257.  
  258. //Your Code here
  259. $pid = pcntl_fork();
  260. if ($pid == -1) {
  261. die('could not fork');
  262. }
  263. else if ($pid)
  264. {
  265. echo("Bye")
  266. }
  267. else
  268. {
  269. //Do Post Processing
  270. }
  271.  
  272. /**
  273. * Performs an async get request (doesn't wait for response)
  274. * Note: One limitation of this approach is it will not work if server does any URL rewriting
  275. */
  276. function async_get($url)
  277. {
  278. $parts=parse_url($url);
  279.  
  280. $fp = fsockopen($parts['host'],
  281. isset($parts['port'])?$parts['port']:80,
  282. $errno, $errstr, 30);
  283.  
  284. $out = "GET ".$parts['path']." HTTP/1.1rn";
  285. $out.= "Host: ".$parts['host']."rn";
  286. $out.= "Connection: Closernrn";
  287. fwrite($fp, $out);
  288. fclose($fp);
  289. }
  290.  
  291. class Daemon extends CI_Controller
  292. {
  293. // Remember to disable CI's csrf-checks for this controller
  294.  
  295. function index( )
  296. {
  297. ignore_user_abort( 1 );
  298. try
  299. {
  300. if ( strcmp( $_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_ADDR'] ) != 0 && !in_array( $_SERVER['REMOTE_ADDR'], $this->config->item( 'proxy_ips' ) ) )
  301. {
  302. log_message( "error", "Daemon called from untrusted IP-address: " . $_SERVER['REMOTE_ADDR'] );
  303. show_404( '/daemon' );
  304. return;
  305. }
  306.  
  307. $this->load->library( 'encrypt' );
  308. $params = unserialize( urldecode( $this->encrypt->decode( $_POST['data'] ) ) );
  309. unset( $_POST );
  310. $model = array_shift( $params );
  311. $method = array_shift( $params );
  312. $this->load->model( $model );
  313. if ( call_user_func_array( array( $this->$model, $method ), $params ) === FALSE )
  314. {
  315. log_message( "error", "Daemon could not call: " . $model . "::" . $method . "()" );
  316. }
  317. }
  318. catch(Exception $e)
  319. {
  320. log_message( "error", "Daemon has error: " . $e->getMessage( ) . $e->getFile( ) . $e->getLine( ) );
  321. }
  322. }
  323. }
  324.  
  325. class Daemon
  326. {
  327. public function execute_background( /* model, method, params */ )
  328. {
  329. $ci = &get_instance( );
  330. // The callback URL (its ourselves)
  331. $parts = parse_url( $ci->config->item( 'base_url' ) . "/daemon" );
  332. if ( strcmp( $parts['scheme'], 'https' ) == 0 )
  333. {
  334. $port = 443;
  335. $host = "ssl://" . $parts['host'];
  336. }
  337. else
  338. {
  339. $port = 80;
  340. $host = $parts['host'];
  341. }
  342. if ( ( $fp = fsockopen( $host, isset( $parts['port'] ) ? $parts['port'] : $port, $errno, $errstr, 30 ) ) === FALSE )
  343. {
  344. throw new Exception( "Internal server error: background process could not be started" );
  345. }
  346. $ci->load->library( 'encrypt' );
  347. $post_string = "data=" . urlencode( $ci->encrypt->encode( serialize( func_get_args( ) ) ) );
  348. $out = "POST " . $parts['path'] . " HTTP/1.1rn";
  349. $out .= "Host: " . $host . "rn";
  350. $out .= "Content-Type: application/x-www-form-urlencodedrn";
  351. $out .= "Content-Length: " . strlen( $post_string ) . "rn";
  352. $out .= "Connection: Closernrn";
  353. $out .= $post_string;
  354. fwrite( $fp, $out );
  355. fclose( $fp );
  356. }
  357. }
  358.  
  359. $this->load->library('daemon');
  360. $this->daemon->execute_background( 'model', 'method', $arg1, $arg2, ... );
  361.  
  362. function curl_request_async($url, $params, $type='GET')
  363. {
  364. $post_params = array();
  365. foreach ($params as $key => &$val) {
  366. if (is_array($val)) $val = implode(',', $val);
  367. $post_params[] = $key.'='.urlencode($val);
  368. }
  369. $post_string = implode('&', $post_params);
  370.  
  371. $parts=parse_url($url);
  372. echo print_r($parts, TRUE);
  373. $fp = fsockopen($parts['host'],
  374. (isset($parts['scheme']) && $parts['scheme'] == 'https')? 443 : 80,
  375. $errno, $errstr, 30);
  376.  
  377. $out = "$type ".$parts['path'] . (isset($parts['query']) ? '?'.$parts['query'] : '') ." HTTP/1.1rn";
  378. $out.= "Host: ".$parts['host']."rn";
  379. $out.= "Content-Type: application/x-www-form-urlencodedrn";
  380. $out.= "Content-Length: ".strlen($post_string)."rn";
  381. $out.= "Connection: Closernrn";
  382. // Data goes in the request body for a POST request
  383. if ('POST' == $type && isset($post_string)) $out.= $post_string;
  384. fwrite($fp, $out);
  385. fclose($fp);
  386. }
  387.  
  388. /-----------GET HTML /--GET IMAGE.........
  389. / /
  390. [Start] GET HTML..............----------------GET IMAGE [Finish]
  391. / /
  392. -----GET HTML....../ -----GET IMAGE....../
  393.  
  394. /-----------GET HTML--GET IMAGE
  395. /
  396. [Start] GET HTML----------------GET IMAGE [Finish]
  397. /
  398. -----GET HTML-----GET IMAGE.../
  399.  
  400. $client = new GuzzleHttpClient();
  401. $promise = $client->requestAsync('GET', 'http://httpbin.org/get');
  402. $promise->then(
  403. function (ResponseInterface $res) {
  404. echo $res->getStatusCode() . "n";
  405. },
  406. function (RequestException $e) {
  407. echo $e->getMessage() . "n";
  408. echo $e->getRequest()->getMethod();
  409. }
  410. );
  411.  
  412. <?php
  413. parse_str("email=myemail@ehehehahaha.com&subject=this is just a test");
  414. $_POST['email']=$email;
  415. $_POST['subject']=$subject;
  416. echo HTTP_Post("http://example.com/mail.php",$_POST);***
  417.  
  418. exit;
  419. ?>
  420. <?php
  421. /*********HTTP POST using FSOCKOPEN **************/
  422. // by ArbZ
  423.  
  424. function HTTP_Post($URL,$data, $referrer="") {
  425.  
  426. // parsing the given URL
  427. $URL_Info=parse_url($URL);
  428.  
  429. // Building referrer
  430. if($referrer=="") // if not given use this script as referrer
  431. $referrer=$_SERVER["SCRIPT_URI"];
  432.  
  433. // making string from $data
  434. foreach($data as $key=>$value)
  435. $values[]="$key=".urlencode($value);
  436. $data_string=implode("&",$values);
  437.  
  438. // Find out which port is needed - if not given use standard (=80)
  439. if(!isset($URL_Info["port"]))
  440. $URL_Info["port"]=80;
  441.  
  442. // building POST-request: HTTP_HEADERs
  443. $request.="POST ".$URL_Info["path"]." HTTP/1.1n";
  444. $request.="Host: ".$URL_Info["host"]."n";
  445. $request.="Referer: $referern";
  446. $request.="Content-type: application/x-www-form-urlencodedn";
  447. $request.="Content-length: ".strlen($data_string)."n";
  448. $request.="Connection: closen";
  449. $request.="n";
  450. $request.=$data_string."n";
  451.  
  452. $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
  453. fputs($fp, $request);
  454. while(!feof($fp)) {
  455. $result .= fgets($fp, 128);
  456. }
  457. fclose($fp); //$eco = nl2br();
  458.  
  459. function getTextBetweenTags($string, $tagname) {
  460. $pattern = "/<$tagname ?.*>(.*)</$tagname>/";
  461. preg_match($pattern, $string, $matches);
  462. return $matches[1]; }
  463. //STORE THE FETCHED CONTENTS to a VARIABLE, because its way better and fast...
  464. $str = $result;
  465. $txt = getTextBetweenTags($str, "span"); $eco = $txt; $result = explode("&",$result);
  466. return $result[1];
  467. <span style=background-color:LightYellow;color:blue>".trim($_GET['em'])."</span>
  468. </pre> ";
  469. }
  470. </pre>
  471.  
  472. $chu = curl_init();
  473.  
  474. curl_setopt($chu, CURLOPT_URL, 'http://www.myapp.com/test.php?someprm=xyz');
  475.  
  476. curl_setopt($chu, CURLOPT_FRESH_CONNECT, true);
  477. curl_setopt($chu, CURLOPT_TIMEOUT, 1);
  478.  
  479. curl_exec($chu);
  480. curl_close($chu);
  481.  
  482. <?php
  483. header("http://mahwebsite.net/myapp.php?var=dsafs");
  484. ?>
Add Comment
Please, Sign In to add comment