SHARE
TWEET

xml_filter.php

wtfbbq Sep 28th, 2015 1,255 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //XMLRPC list checker. Usage: "php xmlrpc_filter.php [input file] [output file] [threads]"
  3. if (!isset($argv[3]))
  4. {
  5. echo 'Usage: php '.$argv[0].' [input file] [output file] [threads]';
  6. exit;
  7. }
  8. function partition($list, $p)
  9. {
  10.     $listlen   = count($list);
  11.     $partlen   = floor($listlen / $p);
  12.     $partrem   = $listlen % $p;
  13.     $partition = array();
  14.     $mark      = 0;
  15.     for ($px = 0; $px < $p; $px++) {
  16.         $incr           = ($px < $partrem) ? $partlen + 1 : $partlen;
  17.         $partition[$px] = array_slice($list, $mark, $incr);
  18.         $mark += $incr;
  19.     }
  20.     return $partition;
  21. }
  22. $part        = array();
  23. $array       = file($argv[1], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  24. $total_lines = count($array);
  25. $childcount  = $argv[3];
  26. $part        = partition($array, $childcount);
  27.  
  28. $shm_id = shmop_open(23377332, "c", 0666, 1024);
  29. shmop_close($shm_id);
  30. for ($i = 0; $i < $childcount; $i++) {
  31.     $pid = pcntl_fork();
  32.     if ($pid == -1) {
  33.         echo "failed to fork on loop $i of forking\n";
  34.         exit;
  35.     } else if ($pid) {
  36.         continue;
  37.     } else {
  38.         $sem    = sem_get(13377331, 1, 0666, 1);
  39.         $shm_id = shmop_open(23377332, "c", 0666, 1024);
  40.         while (true) {
  41.             $results = count($part[$i]);
  42.             $r       = 0;
  43.             foreach ($part[$i] as $line) {
  44.                 if ($r > $results) {
  45.                     break;
  46.                 }
  47.                 $r++;
  48.                 $arrs       = explode(" ", $line);
  49.                 $url        = $arrs[1];
  50.                 $ch         = curl_init();
  51.                 $curlConfig = array(
  52.                     CURLOPT_URL => $url,
  53.                     CURLOPT_RETURNTRANSFER => 1,
  54.                     CURLOPT_SSL_VERIFYPEER => false,
  55.                     CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6',
  56.                     CURLOPT_FOLLOWLOCATION => 1,
  57.                     CURLOPT_TIMEOUT => 1
  58.                 );
  59.                 curl_setopt_array($ch, $curlConfig);
  60.                 $result = curl_exec($ch);
  61.                 curl_close($ch);
  62.                 if (strpos($result, "XML-RPC server accepts POST requests only.") !== FALSE) {
  63.     file_put_contents($argv[2], $line . "\r\n", FILE_APPEND);
  64.                 }
  65.                 sem_acquire($sem);
  66.                 $number = shmop_read($shm_id, 0, 1024);
  67.                 $number = intval($number);
  68.                 $number++;
  69.                 shmop_write($shm_id, str_pad($number, 1024, "\0"), 0);
  70.                 sem_release($sem);
  71.             }
  72.         }
  73.         die;
  74.     }
  75. }
  76.  
  77. $sem    = sem_get(13377331, 1, 0666, 1);
  78. $shm_id = shmop_open(23377332, "c", 0666, 1024);
  79. $total  = 0;
  80. while (true) {
  81.     sem_acquire($sem);
  82.     $number = shmop_read($shm_id, 0, 1024);
  83.     $total += $number;
  84.     echo $number . " R/s " . $total . "/" . $total_lines . " Total                              \r";
  85.     shmop_write($shm_id, str_pad("0", 1024, "\0"), 0);
  86.     sem_release($sem);
  87.     sleep(1);
  88.     if ($total_lines < $total) {
  89.         shell_exec('pkill -f "php ' . $argv[0] . ' ' . $argv[1] . ' ' . $argv[2] . ' ' . $argv[3] . '"');
  90.         echo "Done\n";
  91.     }
  92. }
  93.  
  94. for ($j = 0; $j < $childcount; $j++) {
  95.     $pid = pcntl_wait($status);
  96. }
  97.  
  98. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top