таблица блокировки cron каждые 5 минут

Каждые 5,10,60,3600 минут бегут кроны,
Когда я проверяю журнал ошибок, я вижу очень много исключений взаимоблокировок, почти каждые 5 минут cron отправляет в журнал сообщения об ошибках взаимоблокировок, тайм-аутов и сериализации.

Если я понимаю, что хорошие тупики случаются, когда два или более запросов используют одну и ту же таблицу, что очень возможно в моем коде.

Я использую таблицу MAP 2 раза в каждом кроне, потому что мне нужно отобразить каждую команду,

например:

Челси после картографирования возвращается ФК Челси
Эвертон после картирования возвращается Эвертон

Я получаю команды из больших XML-файлов, когда я убиваю все процессы, cron5 запускается через 2 минуты, что нормально, но когда другие процессы включены, это занимает некоторое время …

Когда я проверяю SHOW OPEN TABLES WHERE in_use>0 я вижу
таблица карт in_use в основном 2, иногда 1.

function getMap($country,$data){
//echo $data . '<br>';
$fdata = $data;
$query = $this->PDO->prepare("CALL GetMap(:data)");
$query->bindParam(':data', $fdata);
$query->execute();
//echo 'DATA: ' . $data. ' RES: '.$res . '<br>';
$res = $query->fetchColumn();
if($res!=''){
$query->closeCursor();
$sql = "UPDATE map SET Country = :country WHERE Base = :base";
$q2 = $this->PDO->prepare($sql);
$q2->bindParam(':country', $country);
$q2->bindParam(':base', $res);
$q2->execute();

//echo $res;
return $res;
}
else
{
$query->closeCursor();
$this->fillMap($country,$fdata);
return $fdata;
}
}

и это процедура для GetMap

DELIMITER //
CREATE PROCEDURE GetMap(p_team VARCHAR(100))
BEGIN
SELECT Base FROM map WHERE
map.Base = p_team OR
Ver1 = p_team OR
Ver2 = p_team OR
Ver3 = p_team OR
Ver4 = p_team OR
Ver5 = p_team OR
Ver6 = p_team OR
Ver7 = p_team OR
Ver8 = p_team OR
Ver9 = p_team OR
Ver10 = p_team OR
Ver11 = p_team OR
Ver12 = p_team;
end //
DELIMITER ;

Теперь мой вопрос, как разблокировать карту таблицы, когда эта таблица заблокирована с помощью php?
Также мне нужно сказать, что я запускаю транзакцию перед чтением xml и фиксирую, когда все будет завершено, поэтому транзакция ждет около 2 минут, когда, вероятно, карта не заблокирована. Это может быть причина, по которой я получаю ошибки тайм-аута, я могу переместить его в цикл или изменить тайм-аут MySQL.

РЕДАКТИРОВАТЬ подробный код:
CHECK $ this-> getMap (); Что в основном используется таблица.

function sendOddsToDb(){
try{
$this->conn->connect();
$this->PDO->beginTransaction();

$countries = $this->OddCountries;
$stmt = $this->PDO->prepare($this->insOdds);
//$dbempty = $this->countRows('odds');
//$this->clrLeagues();
foreach($countries as $country){
$path = "{$this->base}/feeds/odds/{$country}odds.xml";
$odds_feed = $this->parser->parseFile($path);

$fupddate = date('Y-m-d H:i:s',strtotime($odds_feed->attributes()->updated));
$newcountry = '';
if(isset($odds_feed->league)){

$newcountry = $odds_feed->league->attributes()->country;
$fcountries = $this->filterCountries($newcountry);
echo $fcountries . '<br>';
$sql = "select UpdatedDate from odds where Country = '{$fcountries}' order by UpdatedDate desc limit 1";
$res = $this->PDO->query($sql);
$dbupd = date('Y-m-d H:i:s',strtotime($res->fetchColumn()));

if(!$this->sameUpdated($fupddate,$dbupd)){
foreach($odds_feed->league as $league){ //za svaku ligu u fidu
$subid = $league->attributes()->sub_id;

$sportname = '';
$sportid = 0;
if($odds_feed->attributes()->sport == 'soccer' || $odds_feed->attributes()->sport == 'football'){
$sportname = 'football';
$sportid = 1;
}
else{
$sportname = NULL;
}
$lg2 = '';
$lg = $league->attributes()->name;
$ctr = $league->attributes()->country.':';
if(!contains(strtolower($lg),strtolower($ctr))){
$lg2 = ucfirst($ctr) . ' ' . ucfirst($lg);
}
else{
$lg2 = $league->attributes()->name;
}

$flg = $this->getMap2($lg2);
$this->sendLeaguesToDb($league->attributes()->id, $flg ,$fcountries,$sportid,$subid,'tipgin');
foreach($league->match as $match){

$dbdate = date('Y-m-d',strtotime($match->attributes()->date));
$updateddate = date('Y-m-d H:i:s',strtotime($odds_feed->attributes()->updated));
$dbtime = date('H:i:s', strtotime($match->attributes()->time));


$datetime = date('Y-m-d H:i:s',strtotime($dbdate . $dbtime));

$hteam = $this->getMap($fcountries,toShort($match->home->attributes()->name));
$ateam = $this->getMap($fcountries,toShort($match->away->attributes()->name));

//echo $hteam . ' ' . $ateam;
$fixid = 0;
if($match->attributes()->id == 0 || $match->attributes()->id == ''){
if($match->attributes()->alternate_id == 0 || $match->attributes()->id == ''){
$fixid = $match->attributes()->alternate_id_2;
}
else{
$fixid = $match->attributes()->alternate_id;
}
}
else{
$fixid = $match->attributes()->id;
}
//$m = $hteam . ' ' . $ateam;
//var_dump('MATCH: ' . $m . ' HTEAM: ' . mb_detect_encoding($hteam). ' ATEAM: ' . mb_detect_encoding($ateam));
if($match->odds != NULL or $match->odds != ''){
foreach ($match->odds as $odds) {
//var_dump($odd);
if($odds->type != NULL or $odds->type != ''){
foreach ($odds->type as $type) {
if($type->bookmaker != NULL or $type->bookmaker != ''){
foreach ($type->bookmaker as $bookmaker) {
//$oldbook = ;
if($bookmaker->attributes()->name != 'BetClick'){
if($bookmaker->attributes()->name != 'Bodog'){
if($bookmaker->attributes()->name != 'YouWin'){
$homeodds = NULL;
$drawodds = NULL;
$awayodds = NULL;
$numodds = NULL;
$dbhandicap = NULL;
$id2 = '0';
$typename = $this->getMap2($type->attributes()->name);

$fbooks = $this->filterBooks($bookmaker->attributes()->name);

if($typename == 'Over/Under' || $typename == 'Over/Under 1st Half' || $typename == 'Over/Under 2nd Half'){

foreach ($bookmaker->total as $total) { //daj kvote za svaki mec

$numodds = $total->attributes()->name;
foreach($total->odd as $odd){
switch ($odd->attributes()->name) {
case 'Over':
$homeodds = $odd->attributes()->value;
break;
case 'Under':
$awayodds = $odd->attributes()->value;
break;
}

$id2 = $numodds;
}

//echo "HOME TEAM: {$hteam} <BR>";
//echo "AWAY TEAM: {$ateam} <BR>";
/*
echo 'IF ID: ' . $match->attributes()->alternate_id_2 . $league->attributes()->country . " ODDS: {$homeodds} {$drawodds} {$awayodds} TYPE: {$typename}  BOOK: {$fbooks}  ID2: {$id2}" . "<br>";
*/
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$homeodds,$drawodds,
$awayodds, $fbooks, $bookmaker->attributes()->id, $dbhandicap, $id2);
}
}

else if($typename == 'Handicap' || $typename == '3Way Handicap'){
$homeodds = array();
$drawodds = array();
$awayodds = array();
$arrhandicap = array();
$fhandicap = '';

foreach ($bookmaker->handicap as $handicap) { //daj kvote za svaki mec
if (strpos($handicap->attributes()->name,'+') !== false) {
$fhandicap = str_replace('+','',(string)$handicap->attributes()->name);
}else{
$fhandicap = (string)$handicap->attributes()->name;
}
$newhandi = '';
foreach($handicap->odd as $odd){
//$odd = $handicap->odd;
switch ($odd->attributes()->name) {
case '1':
$newhandi = (string)$fhandicap;
$homeodds[(string)$newhandi] =
(string)$odd->attributes()->value;
break;
case 'X':
$newhandi = $fhandicap;
$drawodds[(string)$newhandi] =
(string)$odd->attributes()->value;
break;
case '2':
if (strpos($fhandicap,'-') !== false) { //if negative
$newhandi = str_replace('-','',(string)$fhandicap); //to positive
//echo 'NEGATIVE - OLD: ' . $fhandicap . ' NEW: '.$newhandi . '<br>';
}
elseif($fhandicap=='0'){
$newhandi = '0';
}
else{ //if positive
$newhandi = '-' . (string)$fhandicap; //to negative
//echo 'POSITIVE - OLD: ' . $fhandicap . ' NEW: '.$newhandi . '<br>';
}
$awayodds[(string)$newhandi] = (string)$odd->attributes()->value;
break;
}
$arrhandicap[] = (string)$newhandi;
}
}
//print_r($arrhandicap);
//$arrhandicap[] = sort($dbhandicap);
$inhand = '';
$varhome = '';
$vardraw = '';
$varaway = '';

foreach($arrhandicap as $hand){
$inhand = (string)$hand;
if(isset($hand)){
//echo $typename. ': ' . $hand . '<br>';

if((array_key_exists($inhand,$homeodds)) && (isset($homeodds[$inhand]))){
$varhome = $homeodds[$inhand];
}

if((array_key_exists($inhand,$awayodds)) && (isset($awayodds[$inhand]))){
$varaway = $awayodds[$inhand];
}
if((array_key_exists($inhand,$drawodds)) && (isset($drawodds[$inhand]))){
$vardraw = $drawodds[$inhand];
}

$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$varhome,
$vardraw,$varaway, $fbooks,
$bookmaker->attributes()->id, $hand, $hand);
/*echo 'ELSEIF ID: ' . $match->attributes()->id . $league->attributes()->country . " HOMEODDS: {$varhome}  DRAW: {$vardraw}  AWAYODDS: {$varaway} TYPE: {$typename}  BOOK: {$fbooks}  ID2: {$inhand}" . "<br>";
*/}
}
}
else{
foreach ($bookmaker->odd as $odd) { //daj kvote za svaki mec
if($typename == 'Home/Away'){
$typename = 'Draw No Bet';
}
switch ($odd->attributes()->name) {
case '1':
case '1X':
case 'Yes':
$homeodds = $odd->attributes()->value;
break;
case 'X':
case 'X2':
$drawodds = $odd->attributes()->value;
break;
case '2':
case '12':
case 'No':
$awayodds = $odd->attributes()->value;
break;
}

$id2 = 0;
//echo 'ID: ' . $match->attributes()->alternate_id_2 . $league->attributes()->country . " ODDS: {$homeodds} {$drawodds} {$awayodds} TYPE: {$typename}  BOOK: {$fbooks}  ID2: {$id2}" . "<br>";
}
/*
echo "ELSE HOME TEAM: {$hteam} <BR>";
echo "ELSE AWAY TEAM: {$ateam} <BR>";
*/
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$homeodds,$drawodds,
$awayodds, $fbooks, $bookmaker->attributes()->id, $dbhandicap, $id2);

}
}
}
}
}
}
}
}
}
}
}
}
}
//echo $country.'<br>';
}
}
$this->PDO->commit(); //SAVE
$this->conn->close();
}
catch(Exception $e){
//echo $e;
}
}

private function execOdds($stmt, $matchid, $upddate, $type, $country, $league, $leagueid, $subid, $cup, $sport, $hteam, $hteamid, $ateam, $ateamid, $datetime, $date, $time, $status, $numodds, $homeodds, $drawodds, $awayodds, $book, $bookid, $handicap, $id2){

$event = $hteam . ' - ' . $ateam;

$fcountry = $country;
$fleague = $league;

$stmt->bindParam(':fixturematchid', $matchid);$stmt->bindParam(':updateddate',$upddate);$stmt->bindParam(':type',$type);
$stmt->bindParam(':country',$fcountry);$stmt->bindParam(':league',$fleague);$stmt->bindParam(':leagueid',$leagueid);
$stmt->bindParam(':subid',$subid);
$stmt->bindParam(':cup',$cup);$stmt->bindParam(':eventname',$event);$stmt->bindParam(':sportname',$sport);
$stmt->bindParam(':hometeam', $hteam);$stmt->bindParam(':hometeamid', $hteamid);$stmt->bindParam(':awayteam', $ateam);
$stmt->bindParam(':awayteamid', $ateamid);$stmt->bindParam(':datetime',$datetime);$stmt->bindParam(':date',$date);
$stmt->bindParam(':time',$time);$stmt->bindParam(':status',$status);$stmt->bindParam(':numodds', $numodds);
$stmt->bindParam(':homeodds', $homeodds);$stmt->bindParam(':drawodds',$drawodds);$stmt->bindParam(':awayodds',$awayodds);
$stmt->bindParam(':bookmaker',$book);$stmt->bindParam(':bookmakerid',$bookid);$stmt->bindParam(':handicap', $handicap);
$stmt->bindParam(':id2', $id2);
$stmt->execute(); //EXEC*/
}

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector