Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- make_request('http://www.externalsite.com/script1.php?variable=45'); //example usage
- $output = make_request('http://www.externalsite.com/script2.php?variable=45');
- echo $output; //string output
- $output = file_get_contents('http://www.example.com/');
- echo $output;
- function curl_post_async($url, $params)
- {
- foreach ($params as $key => &$val) {
- if (is_array($val)) $val = implode(',', $val);
- $post_params[] = $key.'='.urlencode($val);
- }
- $post_string = implode('&', $post_params);
- $parts=parse_url($url);
- $fp = fsockopen($parts['host'],
- isset($parts['port'])?$parts['port']:80,
- $errno, $errstr, 30);
- $out = "POST ".$parts['path']." HTTP/1.1rn";
- $out.= "Host: ".$parts['host']."rn";
- $out.= "Content-Type: application/x-www-form-urlencodedrn";
- $out.= "Content-Length: ".strlen($post_string)."rn";
- $out.= "Connection: Closernrn";
- if (isset($post_string)) $out.= $post_string;
- fwrite($fp, $out);
- fclose($fp);
- }
- // $type must equal 'GET' or 'POST'
- function curl_request_async($url, $params, $type='POST')
- {
- foreach ($params as $key => &$val) {
- if (is_array($val)) $val = implode(',', $val);
- $post_params[] = $key.'='.urlencode($val);
- }
- $post_string = implode('&', $post_params);
- $parts=parse_url($url);
- $fp = fsockopen($parts['host'],
- isset($parts['port'])?$parts['port']:80,
- $errno, $errstr, 30);
- // Data goes in the path for a GET request
- if('GET' == $type) $parts['path'] .= '?'.$post_string;
- $out = "$type ".$parts['path']." HTTP/1.1rn";
- $out.= "Host: ".$parts['host']."rn";
- $out.= "Content-Type: application/x-www-form-urlencodedrn";
- $out.= "Content-Length: ".strlen($post_string)."rn";
- $out.= "Connection: Closernrn";
- // Data goes in the request body for a POST request
- if ('POST' == $type && isset($post_string)) $out.= $post_string;
- fwrite($fp, $out);
- fclose($fp);
- }
- <?php
- $request = new cURLRequest('http://www.externalsite.com/script2.php?variable=45');
- $request->getOptions()
- ->set(CURLOPT_TIMEOUT, 5)
- ->set(CURLOPT_RETURNTRANSFER, true);
- // add callback when the request will be completed
- $request->addListener('complete', function (cURLEvent $event) {
- $response = $event->response;
- $content = $response->getContent();
- echo $content;
- });
- while ($request->socketPerform()) {
- // do anything else when the request is processed
- }
- function make_request($url, $waitResult=true){
- $cmi = curl_multi_init();
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_multi_add_handle($cmi, $curl);
- $running = null;
- do {
- curl_multi_exec($cmi, $running);
- sleep(.1);
- if(!$waitResult)
- break;
- } while ($running > 0);
- curl_multi_remove_handle($cmi, $curl);
- if($waitResult){
- $curlInfos = curl_getinfo($curl);
- if((int) $curlInfos['http_code'] == 200){
- curl_multi_close($cmi);
- return curl_multi_getcontent($curl);
- }
- }
- curl_multi_close($cmi);
- }
- <?
- $urls = array_fill(0, 100, 'http://google.com/blank.html');
- function execinbackground($cmd) {
- if (substr(php_uname(), 0, 7) == "Windows"){
- pclose(popen("start /B ". $cmd, "r"));
- }
- else {
- exec($cmd . " > /dev/null &");
- }
- }
- fwite(fopen("urls.txt","w"),implode("n",$urls);
- execinbackground("nodejs urlscript.js urls.txt");
- // { do your work while get requests being executed.. }
- ?>
- var https = require('https');
- var url = require('url');
- var http = require('http');
- var fs = require('fs');
- var dosya = process.argv[2];
- var logdosya = 'log.txt';
- var count=0;
- http.globalAgent.maxSockets = 300;
- https.globalAgent.maxSockets = 300;
- setTimeout(timeout,100000); // maximum execution time (in ms)
- function trim(string) {
- return string.replace(/^s*|s*$/g, '')
- }
- fs.readFile(process.argv[2], 'utf8', function (err, data) {
- if (err) {
- throw err;
- }
- parcala(data);
- });
- function parcala(data) {
- var data = data.split("n");
- count=''+data.length+'-'+data[1];
- data.forEach(function (d) {
- req(trim(d));
- });
- /*
- fs.unlink(dosya, function d() {
- console.log('<%s> file deleted', dosya);
- });
- */
- }
- function req(link) {
- var linkinfo = url.parse(link);
- if (linkinfo.protocol == 'https:') {
- var options = {
- host: linkinfo.host,
- port: 443,
- path: linkinfo.path,
- method: 'GET'
- };
- https.get(options, function(res) {res.on('data', function(d) {});}).on('error', function(e) {console.error(e);});
- } else {
- var options = {
- host: linkinfo.host,
- port: 80,
- path: linkinfo.path,
- method: 'GET'
- };
- http.get(options, function(res) {res.on('data', function(d) {});}).on('error', function(e) {console.error(e);});
- }
- }
- process.on('exit', onExit);
- function onExit() {
- log();
- }
- function timeout()
- {
- console.log("i am too far gone");process.exit();
- }
- function log()
- {
- var fd = fs.openSync(logdosya, 'a+');
- fs.writeSync(fd, dosya + '-'+count+'n');
- fs.closeSync(fd);
- }
- function _async_http_post($url, $json_string) {
- $run = "curl -X POST -H 'Content-Type: application/json'";
- $run.= " -d '" .$json_string. "' " . "'" . $url . "'";
- $run.= " > /dev/null 2>&1 &";
- exec($run, $output, $exit);
- return $exit == 0;
- }
- // Build the multi-curl handle, adding both $ch
- $mh = curl_multi_init();
- // Build the individual requests, but do not execute them
- $chs = [];
- $chs['ID0001'] = curl_init('http://webservice.example.com/?method=say&word=Hello');
- $chs['ID0002'] = curl_init('http://webservice.example.com/?method=say&word=World');
- // $chs[] = ...
- foreach ($chs as $ch) {
- curl_setopt_array($ch, [
- CURLOPT_RETURNTRANSFER => true, // Return requested content as string
- CURLOPT_HEADER => false, // Don't save returned headers to result
- CURLOPT_CONNECTTIMEOUT => 10, // Max seconds wait for connect
- CURLOPT_TIMEOUT => 20, // Max seconds on all of request
- CURLOPT_USERAGENT => 'Robot YetAnotherRobo 1.0',
- ]);
- // Well, with a little more of code you can use POST queries too
- // Also, useful options above can be CURLOPT_SSL_VERIFYHOST => 0
- // and CURLOPT_SSL_VERIFYPEER => false ...
- // Add every $ch to the multi-curl handle
- curl_multi_add_handle($mh, $ch);
- }
- // Execute all of queries simultaneously, and continue when ALL OF THEM are complete
- $running = null;
- do {
- curl_multi_exec($mh, $running);
- } while ($running);
- // Close the handles
- foreach ($chs as $ch) {
- curl_multi_remove_handle($mh, $ch);
- }
- curl_multi_close($mh);
- // All of our requests are done, we can now access the results
- // With a help of ids we can understand what response was given
- // on every concrete our request
- $responses = [];
- foreach ($chs as $id => $ch) {
- $responses[$id] = curl_multi_getcontent($ch);
- curl_close($ch);
- }
- unset($chs); // Finita, no more need any curls :-)
- print_r($responses); // output results
- //Your Code here
- $pid = pcntl_fork();
- if ($pid == -1) {
- die('could not fork');
- }
- else if ($pid)
- {
- echo("Bye")
- }
- else
- {
- //Do Post Processing
- }
- /**
- * Performs an async get request (doesn't wait for response)
- * Note: One limitation of this approach is it will not work if server does any URL rewriting
- */
- function async_get($url)
- {
- $parts=parse_url($url);
- $fp = fsockopen($parts['host'],
- isset($parts['port'])?$parts['port']:80,
- $errno, $errstr, 30);
- $out = "GET ".$parts['path']." HTTP/1.1rn";
- $out.= "Host: ".$parts['host']."rn";
- $out.= "Connection: Closernrn";
- fwrite($fp, $out);
- fclose($fp);
- }
- class Daemon extends CI_Controller
- {
- // Remember to disable CI's csrf-checks for this controller
- function index( )
- {
- ignore_user_abort( 1 );
- try
- {
- if ( strcmp( $_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_ADDR'] ) != 0 && !in_array( $_SERVER['REMOTE_ADDR'], $this->config->item( 'proxy_ips' ) ) )
- {
- log_message( "error", "Daemon called from untrusted IP-address: " . $_SERVER['REMOTE_ADDR'] );
- show_404( '/daemon' );
- return;
- }
- $this->load->library( 'encrypt' );
- $params = unserialize( urldecode( $this->encrypt->decode( $_POST['data'] ) ) );
- unset( $_POST );
- $model = array_shift( $params );
- $method = array_shift( $params );
- $this->load->model( $model );
- if ( call_user_func_array( array( $this->$model, $method ), $params ) === FALSE )
- {
- log_message( "error", "Daemon could not call: " . $model . "::" . $method . "()" );
- }
- }
- catch(Exception $e)
- {
- log_message( "error", "Daemon has error: " . $e->getMessage( ) . $e->getFile( ) . $e->getLine( ) );
- }
- }
- }
- class Daemon
- {
- public function execute_background( /* model, method, params */ )
- {
- $ci = &get_instance( );
- // The callback URL (its ourselves)
- $parts = parse_url( $ci->config->item( 'base_url' ) . "/daemon" );
- if ( strcmp( $parts['scheme'], 'https' ) == 0 )
- {
- $port = 443;
- $host = "ssl://" . $parts['host'];
- }
- else
- {
- $port = 80;
- $host = $parts['host'];
- }
- if ( ( $fp = fsockopen( $host, isset( $parts['port'] ) ? $parts['port'] : $port, $errno, $errstr, 30 ) ) === FALSE )
- {
- throw new Exception( "Internal server error: background process could not be started" );
- }
- $ci->load->library( 'encrypt' );
- $post_string = "data=" . urlencode( $ci->encrypt->encode( serialize( func_get_args( ) ) ) );
- $out = "POST " . $parts['path'] . " HTTP/1.1rn";
- $out .= "Host: " . $host . "rn";
- $out .= "Content-Type: application/x-www-form-urlencodedrn";
- $out .= "Content-Length: " . strlen( $post_string ) . "rn";
- $out .= "Connection: Closernrn";
- $out .= $post_string;
- fwrite( $fp, $out );
- fclose( $fp );
- }
- }
- $this->load->library('daemon');
- $this->daemon->execute_background( 'model', 'method', $arg1, $arg2, ... );
- function curl_request_async($url, $params, $type='GET')
- {
- $post_params = array();
- foreach ($params as $key => &$val) {
- if (is_array($val)) $val = implode(',', $val);
- $post_params[] = $key.'='.urlencode($val);
- }
- $post_string = implode('&', $post_params);
- $parts=parse_url($url);
- echo print_r($parts, TRUE);
- $fp = fsockopen($parts['host'],
- (isset($parts['scheme']) && $parts['scheme'] == 'https')? 443 : 80,
- $errno, $errstr, 30);
- $out = "$type ".$parts['path'] . (isset($parts['query']) ? '?'.$parts['query'] : '') ." HTTP/1.1rn";
- $out.= "Host: ".$parts['host']."rn";
- $out.= "Content-Type: application/x-www-form-urlencodedrn";
- $out.= "Content-Length: ".strlen($post_string)."rn";
- $out.= "Connection: Closernrn";
- // Data goes in the request body for a POST request
- if ('POST' == $type && isset($post_string)) $out.= $post_string;
- fwrite($fp, $out);
- fclose($fp);
- }
- /-----------GET HTML /--GET IMAGE.........
- / /
- [Start] GET HTML..............----------------GET IMAGE [Finish]
- / /
- -----GET HTML....../ -----GET IMAGE....../
- /-----------GET HTML--GET IMAGE
- /
- [Start] GET HTML----------------GET IMAGE [Finish]
- /
- -----GET HTML-----GET IMAGE.../
- $client = new GuzzleHttpClient();
- $promise = $client->requestAsync('GET', 'http://httpbin.org/get');
- $promise->then(
- function (ResponseInterface $res) {
- echo $res->getStatusCode() . "n";
- },
- function (RequestException $e) {
- echo $e->getMessage() . "n";
- echo $e->getRequest()->getMethod();
- }
- );
- <?php
- parse_str("email=myemail@ehehehahaha.com&subject=this is just a test");
- $_POST['email']=$email;
- $_POST['subject']=$subject;
- echo HTTP_Post("http://example.com/mail.php",$_POST);***
- exit;
- ?>
- <?php
- /*********HTTP POST using FSOCKOPEN **************/
- // by ArbZ
- function HTTP_Post($URL,$data, $referrer="") {
- // parsing the given URL
- $URL_Info=parse_url($URL);
- // Building referrer
- if($referrer=="") // if not given use this script as referrer
- $referrer=$_SERVER["SCRIPT_URI"];
- // making string from $data
- foreach($data as $key=>$value)
- $values[]="$key=".urlencode($value);
- $data_string=implode("&",$values);
- // Find out which port is needed - if not given use standard (=80)
- if(!isset($URL_Info["port"]))
- $URL_Info["port"]=80;
- // building POST-request: HTTP_HEADERs
- $request.="POST ".$URL_Info["path"]." HTTP/1.1n";
- $request.="Host: ".$URL_Info["host"]."n";
- $request.="Referer: $referern";
- $request.="Content-type: application/x-www-form-urlencodedn";
- $request.="Content-length: ".strlen($data_string)."n";
- $request.="Connection: closen";
- $request.="n";
- $request.=$data_string."n";
- $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
- fputs($fp, $request);
- while(!feof($fp)) {
- $result .= fgets($fp, 128);
- }
- fclose($fp); //$eco = nl2br();
- function getTextBetweenTags($string, $tagname) {
- $pattern = "/<$tagname ?.*>(.*)</$tagname>/";
- preg_match($pattern, $string, $matches);
- return $matches[1]; }
- //STORE THE FETCHED CONTENTS to a VARIABLE, because its way better and fast...
- $str = $result;
- $txt = getTextBetweenTags($str, "span"); $eco = $txt; $result = explode("&",$result);
- return $result[1];
- <span style=background-color:LightYellow;color:blue>".trim($_GET['em'])."</span>
- </pre> ";
- }
- </pre>
- $chu = curl_init();
- curl_setopt($chu, CURLOPT_URL, 'http://www.myapp.com/test.php?someprm=xyz');
- curl_setopt($chu, CURLOPT_FRESH_CONNECT, true);
- curl_setopt($chu, CURLOPT_TIMEOUT, 1);
- curl_exec($chu);
- curl_close($chu);
- <?php
- header("http://mahwebsite.net/myapp.php?var=dsafs");
- ?>
Add Comment
Please, Sign In to add comment