我为一个名为xat的网站制作了一个“ID生成器”,现在它可以在任何最新的Windows机器上运行。但我不明白为什么当我在Linux Debian服务器上运行它时,我得到了:
root@vps:/idgen# php get.php
[3:45:42 PM] Connected to MySQL server
[3:45:42 PM] Starting ID Generator With 0 IDs to begin with.
PHP Fatal Error: Call to undefined function curl_init() in /idgen/get.php on line 70
root@vps:/idgen#
(我是linux机器的新手。我做了一些研究,但直到不明白它:我的代码很长。它的
<?php
set_time_limit(0);
ini_set('display_error', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');
$idGen = new IDGenerator;
$loop = 1;
while(true)
{
switch(@$argv[1]) {
case '0':
default:
$list = fopen('proxies.txt', 'r');
while(!feof($list))
{
$proxy = fgets($list);
$idGen->generate($proxy);
}
fclose($list);
break;
}
$loop++;
usleep(50000);
$idGen->report('Starting loop #'.$loop);
}
class IDGenerator
{
public $sql = NULL;
public $one = array('1','2','3','4','5','6','7','8','9','0');
public $two = array('11','22','33','44','55','66','77','88','99','00');
public $three = array('111','222','333','444','555','666','777','888','999','000');
public $four = array('0000','1010','1111','1212','1313','1414','1515','1616','1717','1818','1919','2020','2121','2222','2323','2424','2525','2626','2727','2828','2929','3030','3131','3232','3333','3434','3535','3636','3737','3838','3939','4040','4141','4242','4343','4444','4545','4646','4747','4848','4949','5050','5151','5252','5353','5454','5555','5656','5757','5858','5959','6060','6161','6262','6363','6464','6565','6666','6767','6868','6969','7070','7171','7272','7373','7474','7575','7676','7777','7878','7979','8080','8181','8282','8383','8484','8585','8686','8787','8888','8989','9090','9191','9292','9393','9494','9595','9696','9797','9898','9999');
public $five = array('00000','10101','11111','12121','13131','14141','15151','16161','17171','18181','19191','20202','21212','22222','23232','24242','25252','26262','27272','28282','29292','30303','31313','32323','33333','34343','35353','36363','37373','38383','39393','40404','41414','42424','43434','44444','45454','46464','47474','48484','49494','50505','51515','52525','53535','54545','55555','56565','57575','58585','59595','60606','61616','62626','63636','64646','65656','66666','67676','68686','69696','70707','71717','72727','73737','74747','75757','76767','77777','78787','79797','80808','81818','82828','83838','84848','85858','86868','87878','88888','89898','90909','91919','92929','93939','94949','95959','96969','97979','98989','99999');
public $six = array('000000','101010','111111','121212','131313','141414','151515','161616','171717','181818','191919','202020','212121','222222','232323','242424','252525','262626','272727','282828','292929','303030','313131','323232','333333','343434','353535','363636','373737','383838','393939','404040','414141','424242','434343','444444','454545','464646','474747','484848','494949','505050','515151','525252','535353','545454','555555','565656','575757','585858','595959','606060','616161','626262','636363','646464','656565','666666','676767','686868','696969','707070','717171','727272','737373','747474','757575','767676','777777','787878','797979','808080','818181','828282','838383','848484','858585','868686','878787','888888','898989','909090','919191','929292','939393','949494','959595','969696','979797','989898','999999');
public $seven = array('0000000','1010101','1111111','1212121','1313131','1414141','1515151','1616161','1717171','1818181','1919191','2020202','2121212','2222222','2323232','2424242','2525252','2626262','2727272','2828282','2929292','3030303','3131313','3232323','3333333','3434343','3535353','3636363','3737373','3838383','3939393','4040404','4141414','4242424','4343434','4444444','4545454','4646464','4747474','4848484','4949494','5050505','5151515','5252525','5353535','5454545','5555555','5656565','5757575','5858585','5959595','6060606','6161616','6262626','6363636','6464646','6565656','6666666','6767676','6868686','6969696','7070707','7171717','7272727','7373737','7474747','7575757','7676767','7777777','7878787','7979797','8080808','8181818','8282828','8383838','8484848','8585858','8686868','8787878','8888888','8989898','9090909','9191919','9292929','9393939','9494949','9595959','9696969','9797979','9898989','9999999');
public $eight = array('00000000','10101010','11111111','12121212','13131313','14141414','15151515','16161616','17171717','18181818','19191919','20202020','21212121','22222222','23232323','24242424','25252525','26262626','27272727','28282828','29292929','30303030','31313131','32323232','33333333','34343434','35353535','36363636','37373737','38383838','39393939','40404040','41414141','42424242','43434343','44444444','45454545','46464646','47474747','48484848','49494949','50505050','51515151','52525252','53535353','54545454','55555555','56565656','57575757','58585858','59595959','60606060','61616161','62626262','63636363','64646464','65656565','66666666','67676767','68686868','69696969','70707070','71717171','72727272','73737373','74747474','75757575','76767676','77777777','78787878','79797979','80808080','81818181','82828282','83838383','84848484','85858585','86868686','87878787','88888888','89898989','90909090','91919191','92929292','93939393','94949494','95959595','96969696','97979797','98989898','99999999');
public $nine = array('000000000','101010101','111111111','121212121','131313131','141414141','151515151','161616161','171717171','181818181','191919191','202020202','212121212','222222222','232323232','242424242','252525252','262626262','272727272','282828282','292929292','303030303','313131313','323232323','333333333','343434343','353535353','363636363','373737373','383838383','393939393','404040404','414141414','424242424','434343434','444444444','454545454','464646464','474747474','484848484','494949494','505050505','515151515','525252525','535353535','545454545','555555555','565656565','575757575','585858585','595959595','606060606','616161616','626262626','636363636','646464646','656565656','666666666','676767676','686868686','696969696','707070707','717171717','727272727','737373737','747474747','757575757','767676767','777777777','787878787','797979797','808080808','818181818','828282828','838383838','848484848','858585858','868686868','878787878','888888888','898989898','909090909','919191919','929292929','939393939','949494949','959595959','969696969','979797979','989898989','999999999');
public $proxy;
public $cp = array();
public function __construct()
{
include('database.class.php');
$this->sql = new Database($this);
$this->report('Connected to MySQL Server');
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report('Starting ID Generator With '.$nc.' IDs to begin with.');
}
public function generate($ip='111.111.111.111',$port=1, $elapsed=0) {
if( ( $elapsed - time() ) >= 0 && $elapsed != 0) {
//This causes MAJOR terminal/CMD flood.
// $this->report('Proxy: '.$ip.':'.$port.' will be trying again in '.$this->sec2hms($elapsed-time()));
return;
}
$this->cp = array(
'ip' => $ip,
'port' => $port
);
$proxy = $ip.':'.$port;
$tries = 0;
$xData = '';
$timeout = 3;
// echo "Tries -> ";
while($xData=='' && $tries < 3) {
$ch = curl_init(); //curl init :D
curl_setopt($ch, CURLOPT_URL, 'http://xat.com/web_gear/chat/auser3.php?t='.rand(100000000000,1000000000000000000000000000000000)); //url
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$rdata = $data;
if(@$data{0} == '<') {
return;//Bad Proxy Detected.
}
if(strpos($data, 'Not Found') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
}
if($data != '&UserId=0&k1=0&k2=0') {
if(strpos($data, '&k2=0') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
} else {
$xData = $data;
}
} else {
echo $data."\n";
}
$tries++;
}
if($xData=='') {
return;//Dead Proxy
}
if (strlen($data) < 50 && $data) {
$this->check($data);
}
}
public function sec2hms($sec, $padHours = false) {
@$hms = "";
@$days = intval($sec/86400);
if($days > 0 ) {
if($days == 1) {
@$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$days.' Day');
} else {
@$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$days.' Days');
}
}
@$sec-= ($days*86400);
@$hours = intval(intval($sec) / 3600);
if($hours > 0) {
if($days > 0) { @$s = ', '; }
if($hours == 1) {
@$hms .= @$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$hours.' Hour');
} else {
@$hms .= @$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':@$hours.' Hours');
}
}
@$minutes = intval(($sec / 60) % 60);
if($minutes > 0) {
if($hours > 0) { @$d = ', '; }
if($minutes == 1) {
@$hms .= @$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minute';
} else {
@$hms .= @$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minutes';
}
}
@$seconds = intval($sec % 60);
if($seconds > 0) {
if($minutes > 0) { @$p = ', '; }
if($seconds == 1) {
@$hms .= @$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Second';
} else {
@$hms .= @$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Seconds';
}
}
return @$hms;
}
public function report($data) {
$time = date('g:i:s A', time());
echo "[$time] $data\n";
}
public function rwrite($data) {
$auser = $this->idFix($data);
$check = $this->CheckForID($auser['UserId']);
if($check) {
if(str_replace(' ', '', $auser['UserId'])!='') {
$this->report($auser['UserId'].' already exists in the database.');
}
return;
}
$auser['rare'] = true;
$auser['price'] = $this->determinePrice($auser['UserId']);
$auser['reglink'] = 'http://xat.com/web_gear/chat/register.php?UserId='.$auser['UserId'].'&k2='.$auser['k2'].'&mode=1';
$auser['added'] = date('l, F jS Y g:i:s A');
$this->sql->insert('ids', $auser);
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report($auser['UserId'].' added as a rare id, we have '.$nc.' ids now.');
}
public function write($data) {
$auser = $this->idFix($data);
$check = $this->CheckForID($auser['UserId']);
if($check) {
if(str_replace(' ', '', $auser['UserId'])!='') {
$this->report($auser['UserId'].' already exists in the database.');
}
return;
}
$auser['rare'] = false;
$auser['added'] = date('l, F jS Y g:i:s A');
$auser['price'] = $this->determinePrice($auser['UserId']);
$auser['reglink'] = 'http://xat.com/web_gear/chat/register.php?UserId='.$auser['UserId'].'&k2='.$auser['k2'].'&mode=1';
$this->sql->insert('ids', $auser);
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report($auser['UserId'].' added as a normal id, we have '.$nc.' ids now.');
}
public function determinePrice($id='0') {
if($id=='0' || !is_numeric($id)) {
return '0';//0 xats cuz of no id.
}
$price = 100;//Start the bid off at 100 xats, NO FREE IDS.
if ( $this->strposa($id, $this->nine) ) {
$price = $price + 900;// never mind that, make it 1k
} else
if ( $this->strposa($id, $this->eight) ) {
$price = $price + 800;
} else
if ( $this->strposa($id, $this->seven) ) {
$price = $price + 700;
} else
if ( $this->strposa($id, $this->six) ) {
$price = $price + 600;
} else
if ( $this->strposa($id, $this->five) ) {
$price = $price + 500;
} else
if ( $this->strposa($id, $this->four) ) {
$price = $price + 150;
} else
if ( $this->strposa($id, $this->three) ) {
$price = $price + 20;
}
return $price;
}
public function idFix($data='&UserId=0&k1=0&k2=0')
{
if($data=='') { $data = '&UserId=0&k1=0&k2=0'; }
$user = explode('&', $data);
return array(
'UserId'=> str_replace('UserId=', '', @$user[1]),
'k1' => str_replace('k1=', '', @$user[2]),
'k2'=> str_replace('k2=', '', @$user[3])
);
}
public function randomString($chars=32) {
$letters = range('a','z');
$caps = range('A', 'Z');
$numbers = range(0, 9);
$array = array_merge(range('a','z'), array_merge(range('A', 'Z'), range(0,9)));
for($x=0;$x<=100;$x++) {
shuffle($array);//shuffle it up really good =D
}
$i = 0;
$ch = '';
for($index=0; $index<$chars; $index++) {
$ch .= $array[ array_rand($array) ];
}
return $ch;
}
public function CheckForID($id=0)
{
if($id==0) return true;
$check = $this->sql->select('*', 'ids', 'UserId='.$id);
if(!$check)
{
return false;
}
return true;
}
public function check($data='&UserId=0&k1=0&k2=0') {
if($data=='') { $data = '&UserId=0&k1=0&k2=0'; }
$auser = $this->idFix($data);
$this->storage($auser['UserId'], $data);
}
public function storage($id, $data) {
if ($this->strposa($id,$this->nine) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->eight) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->seven) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->six) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->five) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->four) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->three) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else {
$this->write($data);
return true;
}
return false;
}
public function reset() {
die('restart me!');
}
public function strposa($haystack, $needles=array(), $offset=1) {
$chr = array();
foreach($needles as $needle) {
$res = strpos($haystack, $needle);
if ($res !== false)
{
$chr[$needle] = $res;
}
}
if(empty($chr))
{
return false;
}
return min($chr);
}
}
?>
答案 0 :(得分:2)
PHP致命错误实际上与Linux本身无关,它是PHP中缺少的cURL扩展。
要回到Debian方面,要安装扩展,请在命令行/终端中运行:
sudo apt-get install php5-curl
注意:不要将互联网上的内容复制粘贴到您的控制台中。您可能也在复制隐藏文本,并可能危及您的系统。来吧,输入它。