function recognize(
$filename,
$domain,
$mod,
$is_verbose,
$mp3=null,
$rtimeout = 5,
$mtimeout = 120
)
{
if (!file_exists($filename))
{
if ($is_verbose) echo "file $filename not found\n";
return false;
}
if(!isset($mp3))
{
$postdata = array(
'method' => 'post',
'file' => file_get_contents($filename),
'filename' => $filename,
'ParallelMode' => "true",
'CapMonsterModule' => $mod
);
}else{
$postdata = array(
'method' => 'post',
'file' => "@".$filename,
'ParallelMode' => "true",
'CapMonsterModule' => $mod
);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://$domain/in.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
if (curl_errno($ch))
{
if ($is_verbose) echo "CURL returned error: ".curl_error($ch)."\n";
return false;
}
curl_close($ch);
if (strpos($result, "ERROR")!==false)
{
if ($is_verbose) echo "server returned error: $result\n";
return false;
}
else
{
$ex = explode("|", $result);
$captcha_id = $ex[1];
if ($is_verbose) echo "captcha sent, got captcha ID $captcha_id\n";
$waittime = 0;
if ($is_verbose) echo "waiting for $rtimeout seconds\n";
sleep($rtimeout);
while(true)
{
$result = file_get_contents("http://$domain/res.php?key=".$apikey.'&action=get&id='.$captcha_id);
if (strpos($result, 'ERROR')!==false)
{
if ($is_verbose) echo "server returned error: $result\n";
return false;
}
if ($result=="CAPCHA_NOT_READY")
{
if ($is_verbose) echo "captcha is not ready yet\n";
$waittime += $rtimeout;
if ($waittime>$mtimeout)
{
if ($is_verbose) echo "timelimit ($mtimeout) hit\n";
break;
}
if ($is_verbose) echo "waiting for $rtimeout seconds\n";
sleep($rtimeout);
}
else
{
$ex = explode('|', $result);
if (trim($ex[0])=='OK') return trim($ex[1]);
}
}
return false;
}
}