PHP - proxy checker multi-threaded - php

I already made my personal single thread proxy checker using php,but I couldnt make it multi-thread,some days ago,I found one checker using multi-thread on github,can someone help to change it to save the good proxies into a file (ip:port format)?
https://raw.githubusercontent.com/samuel-allan/FastProxyChecker/master/checker.php
What i have tried:
original line 91:
echo json_encode($arr);
changed to:
$json = json_decode($arr);
$good_proxie = $json['arr']['result']['proxy']['ip'];
echo "$good_proxie";

I did not checked it, but think it'll work ^_^
function CheckMultiProxy($proxies, $timeout, $proxy_type)
{
$data = array();
foreach($proxies as $proxy)
{
$parts = explode(':', trim($proxy));
$url = strtok(curPageURL(),'?');
$data[] = $url . '?ip=' . $parts[0] . "&port=" . $parts[1] . "&timeout=" . $timeout . "&proxy_type=" . $proxy_type;
}
$results = multiRequest($data);
$holder = array();
foreach($results as $result)
{
$holder[] = json_decode($result, true)["result"];
}
$arr = array("results" => $holder);
foreach ($arr['results'] as $proxy) {
if ($proxy['success']) {
file_put_contents('YOUR_FILE_HERE', $proxy['proxy']['ip'].':'.$proxy['proxy']['port'].' '.$proxy['proxy']['type'].PHP_EOL, FILE_APPEND);
}
}
echo json_encode($arr);
}

Related

How to work with this JSON, including array

I tried to work with basic, few param. JSON code and there wasn't any problem with that.
BUT now i need work with this "advanced" JSON and I am kinda lost
{
"code":"success",
"username":"x",
"nodes":[
{
"id":"68",
"time":987
},
{
"id":"69",
"time":987
}
]
}
When i tried to get the values into PHP variable with previou code, I wasn't able to get ID and TIME, CODE and SUCCESS isn't problem.
PHP code I used:
$url = "example.com";
$url = str_replace(" ","%20",$url);
$json = #file_get_contents($url);
$details = json_decode($json, TRUE);
// print_r($details);
echo $details[code];
Thank you guys!
<?php
$url = "example.com";
$url = str_replace(" ","%20",$url);
$json = #file_get_contents($url);
$details = json_decode($json, TRUE);
if (is_array($details['nodes'])) {
echo "node count: " . count($details['nodes']) . "<br />";
foreach ($details['nodes'] as $node) {
echo "id: " . $node['id'] . "<br />";
echo "time: " . $node['time'] . "<br />";
}
}

Wrong Foreach cycle

i am doing something wrong with my foreach cycle. But looks my knowledge is not enugh to figure out what's wrong. My code is pretty simple:
$xnl_file = "xml.xml";
$xml = simplexml_load_file($xnl_file);
$my_file = 0;
foreach ($xml as $value){
var_dump($value);
$CountryOrganizationId = "<CountryOrganizationId>".$xml->Partnership->CountryOrganizationId."</CountryOrganizationId>";
$PartnershipId = "<PartnershipId>".$xml->Partnership->PartnershipId."</PartnershipId>";
$OwnerId = "<OwnerId>".$xml->Partnership->OwnerId."<OwnerId>";
$PartnerIdList = "<PartnerIdList><String>".$xml->Partnership->PartnerIdList->String."</String></PartnerIdList>";
$CountryOrganizationId_contact = "<Contract><CountryOrganizationId>".$xml->Partnership->Contract->CountryOrganizationId."</CountryOrganizationId>";
$ContractId = "<ContractId>".$xml->Partnership->Contract->ContractId."</ContractId>";
$data = "<Partnership>".$CountryOrganizationId.$PartnershipId.$OwnerId.$PartnerIdList.$CountryOrganizationId_contact.$ContractId.$Role1.$Category1.$Rate1.
$Role2.$Category2.$Rate2.$Role3.$Category3.$Rate3."</Partnership>";
echo $data;
}
I am getting data from XML and try to parse it on multiple one, but this just copy same data again and again. I am not sure what i am doing wrong. In my opinion data should rewrite each other every time cycle is doing same but they are not changing. At echo $data i get as many results as i should, problem is just they are same.
If I var_dump $value at start i get nice result that data are coming to cycle but why the output is the same all the time?
Please can somebody give me advise?
Thanks
The $value variable is never used, you're always using the $xml. Try it like:
$xnl_file = "xml.xml";
$xml = simplexml_load_file($xnl_file);
$my_file = 0;
foreach ($xml as $value){
var_dump($value);
$CountryOrganizationId = "<CountryOrganizationId>" . $value->CountryOrganizationId . "</CountryOrganizationId>";
$PartnershipId = "<PartnershipId>" . $value->PartnershipId . "</PartnershipId>";
$OwnerId = "<OwnerId>" . $value->OwnerId . "<OwnerId>";
$PartnerIdList = "<PartnerIdList><String>" . $value->PartnerIdList->String . "</String></PartnerIdList>";
$CountryOrganizationId_contact = "<Contract><CountryOrganizationId>" . $value->Contract->CountryOrganizationId . "</CountryOrganizationId>";
$ContractId = "<ContractId>" . $value->Contract->ContractId . "</ContractId>";
$data = "<Partnership>" . $CountryOrganizationId . $PartnershipId . $OwnerId . $PartnerIdList . $CountryOrganizationId_contact .
$ContractId . $Role1 . $Category1 . $Rate1 . $Role2 . $Category2 . $Rate2 . $Role3 . $Category3 . $Rate3 .
"</Partnership>"afdsf
echo $data;
}
Concat $data to its previous value { $data .= "......"}
foreach ($xml as $value)
{
var_dump($value);
$CountryOrganizationId = "<CountryOrganizationId>".$xml->Partnership->CountryOrganizationId."</CountryOrganizationId>";
$PartnershipId = "<PartnershipId>".$xml->Partnership->PartnershipId."</PartnershipId>";
$OwnerId = "<OwnerId>".$xml->Partnership->OwnerId."<OwnerId>";
$PartnerIdList = "<PartnerIdList><String>".$xml->Partnership->PartnerIdList->String."</String></PartnerIdList>";
$CountryOrganizationId_contact = "<Contract><CountryOrganizationId>".$xml->Partnership->Contract->CountryOrganizationId."</CountryOrganizationId>";
$ContractId = "<ContractId>".$xml->Partnership->Contract->ContractId."</ContractId>";
$data .= "<Partnership>".$CountryOrganizationId.$PartnershipId.$OwnerId.$PartnerIdList.$CountryOrganizationId_contact.$ContractId.$Role1.$Category1.$Rate1.
$Role2.$Category2.$Rate2.$Role3.$Category3.$Rate3."</Partnership>";
}
echo $data;

PHP json, finding info and linking it with 4chan api

If I wanted to echo the link of a general thread on 4chan.
Here's what I was thinking of, however I have no idea on what to do
$jsonurl = "http://a.4cdn.org/vg/catalog.json";
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);
foreach( $json_output as $no )
{
if(strpos(sub, 'DOTA')) { //Not sure how I would do this
//echo the "no" of it in the json
}
}
Had to look at the JSON data to see what you were looking for. Give this a try
$jsonurl = "http://a.4cdn.org/g/catalog.json";
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);
foreach ($json_output as $page) {
foreach($page->threads as $thread) {
if (isset($thread->sub)) {
$sub = $thread->sub;
$no = $thread->no;
echo $sub . ', Thread Number: ' . $no . '<br />';
/*
if (strpos($sub, 'DOTA') !== false) {
echo 'Found DOTA!!! Thread Number is: ' . $thread->no;
}
*/
}
}
}
You should study the JSON data that you receive in order to know how to extract the data. This is one way of doing it:
foreach( $json_output as $page ) {
foreach ($page->threads as $t) {
echo 'http://boards.4chan.org/vg/res/' . $t->no . ', ';
}
}

PHP issue reading huge data from txt files

I'm running a php script that reads from some pipe-delimited txt files, those files contain around 22,000 records. I'm using PHP file() function to read those files, BTW the files have some inter-relation too, I'm pasting the code here for better understanding
public function getGames()
{
$resource = self::DATAFILES.'Product.txt';
$games = array_slice($this->readFile($resource), 1);
$data = array();
$count = 1;
foreach($games as &$records)
{
$game = new Game();
$attributes = explode($this->delimiter,$records);
$game->api = (int) $attributes[0];
$game->console_id = (string) $attributes[1];
$game->title = (string) $this->getTitle($attributes[2]);
$game->barcode = (string) $attributes[4];
$game->image = $this->getCoverImage($attributes[0]);
$game->releateDate = strtotime($attributes[8]);
$data[] = $game;
//if($count == 100): break; else: $count++; endif;
}
print '<pre>'; print_r($data);
}
public function getTitle($titleID)
{
$resource = self::DATAFILES.'Title.txt';
$titles = array_slice($this->readFile($resource), 1);
foreach($titles as $records)
{
$attributes = explode($this->delimiter,$records);
$pattern = '/^' . preg_quote($attributes[0], '/') . '$/';
if (preg_match($pattern, $titleID))
{
return $attributes[2];
break;
}
}
}
public function getCoverImage($gameID)
{
$resource1 = self::DATAFILES.'ProductImage.txt';
$coverImages = array_slice($this->readFile($resource1), 1);
foreach($coverImages as $img_records)
{
$image_attributes = explode($this->delimiter,$img_records);
$pattern1 = '/^' . preg_quote($image_attributes[0], '/') . '$/';
$pattern2 = '/^' . preg_quote($image_attributes[3], '/') . '$/';
if (preg_match($pattern1, $gameID) && preg_match($pattern2, 'Cover'))
{
return $image_attributes[2];
break;
}
}
So the problem I'm facing here is that - when I run that script it will just go on and on nothing happens i.e never throws any error neither print the returned array, however when I limit's the loop iteration up to 100 it works which means nothing wrong with the code so I thought perhaps, php script execution time making trouble so I changed it to max_execution_time = 0 - but still not getting the results. Any help or suggestion, would love hear that.. :)
BTW I'm using Xampp Apache for my local dev !

php foreach not working properly with explode

Ok some php code below.
$user_pass = "
vortex90:OPFY4MB8
jimmy3:3M7ISWof
dave-ish-mental:YEnMMXua
cindybaby:rRHxrErp
claire-x:H4VrT8Xx
icemonster:ODId9N17
";
$token = 'token';
$ex = explode("\r", $user_pass);
foreach ($ex as $info) {
print "username=" . str_replace(":", "&password=", $info) . "&token=" . $token . "\n";
}
What i want the foreach() to do is show for each explode
username=username&password=password&token=token
But below is what gets returned.
vortex90&password=OPFY4MB8
jimmy3&password=3M7ISWof
dave-ish-mental&password=YEnMMXua
cindybaby&password=rRHxrErp
claire-x&password=H4VrT8Xx
icemonster&password=ODId9N17
Why is it not returning as expected? all answers welcome.
This works for me, it is better practice to use PHP_EOL:
$token = "bla";
$user_pass = "
vortex90:OPFY4MB8
jimmy3:3M7ISWof
dave-ish-mental:YEnMMXua
cindybaby:rRHxrErp
claire-x:H4VrT8Xx
icemonster:ODId9N17
";
$explode = explode(PHP_EOL, $user_pass);
foreach($explode as $i) {
$replace_shit = str_replace(array("\r","\n",":"), array("","","&password="), $i);
$user_info = "username=".$replace_shit."&token=".$token."<br>\n";
echo $user_info;
}
DEMO: http://sandbox.onlinephpfunctions.com/code/02f6663f7fa69c158a90fde2ab421cf52a78f7ce

Categories