JuanFernandoz JuanFernandoz - 7 days ago 5
PHP Question

Convert this curl to multi PHP

I have this code and I want made 10 curl connections like this with multi but I don't know how to that with this specific code:

What the code does?


  1. Make a curl requiest to an .asp page

  2. Uses the result to send some data in a form ($ciudad) then the page get this submit and make an internal request and show an result.

  3. Output the final result of that.

    function curl($header,$encoded,$cookie){
    $options = array(
    CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
    CURLOPT_TIMEOUT => 120,
    //CURLOPT_REFERER => '',
    //CURLOPT_HTTPHEADER => $header,
    CURLOPT_COOKIE => $cookie,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $encoded,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => false,
    CURLOPT_FOLLOWLOCATION => true,
    );
    $ch = curl_init("http://procesos.ramajudicial.gov.co/consultaprocesos/consultap.aspx");
    curl_setopt_array( $ch, $options );
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
    }

    $cookie = "";
    foreach($_COOKIE as $k => $v)
    $cookie .= $k."=".$v.";";
    $cookie = substr($cookie,0,strlen($cookie)-1);

    $encoded = '';
    foreach($_POST as $name => $value) {
    $encoded .= urlencode($name).'='.urlencode($value).'&';
    }

    $lk = "http://procesos.ramajudicial.gov.co/consultaprocesos/";

    $header[] = 'User-Agent: '.$_SERVER['HTTP_USER_AGENT'];
    $header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text /html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
    $header[] = 'Accept-Language: en-us,en;q=0.5';
    $header[] = 'Accept-Encoding: gzip,deflate';
    $header[] = 'Connection: keep-alive';
    $header[] = 'Cookie : '.$cookie;
    $header[] = 'Content-Type: application/x-www-form-urlencoded';

    $output = curl($header,$encoded,$cookie);

    $CIUDAD = urlencode("Medellin"); // to change
    $CORPORACION = urlencode("JUZGADOS CIVILES MUNICIPALES DE MEDELLIN"); // to change
    $DIGITOS = $numsus;

    // BEGIN STEP 1
    $__VIEWSTATE = 'id="__VIEWSTATE" value="';
    $i = stripos($output,$__VIEWSTATE) + strlen($__VIEWSTATE);
    $j = stripos($output,'"',$i);
    $__VIEWSTATE = substr($output,$i,$j-$i);

    $__EVENTVALIDATION = 'id="__EVENTVALIDATION" value="';
    $i = stripos($output,$__EVENTVALIDATION) + strlen($__EVENTVALIDATION);
    $j = stripos($output,'"',$i);
    $__EVENTVALIDATION = substr($output,$i,$j-$i);

    $encoded = '__EVENTTARGET=DropDownList1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE='.urlencode($__VIEWSTATE).'&__EVENTVALIDATION='.urlencode($__EVENTVALIDATION).'&DropDownList1='.$CIUDAD.'&TextBox13=';

    $output = curl($header,$encoded,$cookie);


Answer

It would be good if you could just have ten threads using whatever works best for you, file_get_contents most probably ...

https://github.com/krakjoe/pthreads

You can have Threads :)

Enjoy ...