A
A
Alex Alex2016-02-17 15:24:10
PHP
Alex Alex, 2016-02-17 15:24:10

How to speed up php script?

There is a database in it of 100-1000 accounts. And each account must perform some action.

<?php
set_time_limit(0);
$res=mysqli_query($CONNECT, "SELECT * FROM `account`");
while($row=mysqli_fetch_assoc($res)){
$login=$row['login'];
$likes=trim($row['id']);
$account=trim($row['id_account']);   
$user=trim($row['id_users']);
$p1=trim($row['proxy']);   
$p2=trim($row['proxy_login']);
if($row['work']==1){
if(trim($row['like'])==1)
{
$respons=send('http://site.ru/elike','',1,$user,$account,$p1,$p2);
preg_match('/points\'>(.*?)</', $respons, $balance);
$respons=send('http://site.ru/wait.php','',1,$user,$account,$p1,$p2);
preg_match('/link=(.*?)\n/', $respons, $like);
if ($like[1]==''){
echo $login.' нету лайков<br>';   
}else {
$respons=send(trim($like[1]),'',1,$user,$account,$p1,$p2);
$last=$like[1];
preg_match('/media\?id=(.*?)"/i', $respons, $id);
$respons=like('https://www.instagram.com/web/likes/'.trim($id[1]).'/like/',1,0,$user,$account,$p1,$p2);
$json = json_decode($respons);
if ($json->status=='ok'){
mysqli_query($CONNECT, "UPDATE `account`  SET `balance` = '$balance[1]' WHERE `id` = '$likes'");
mysqli_query($CONNECT, "UPDATE `account`  SET `last` = '$last' WHERE `id` = '$likes'");
mysqli_query($CONNECT, "UPDATE `account`  SET `last_work` = 'like' WHERE `id` = '$likes'");
$respons=send('http://socgain.com/check/check_likes.php','',1,$user,$account,$p1,$p2);
echo $login.' лайк<br>';
}
else {
echo $login.' ошибка<br>';   
}   
}
}
}
}
?>

But if there are more than 50 accounts in the database, the script just hangs and gives a 500 error.
The script sorts through the instagram accounts in the database and puts likes (via Curl with a proxy).
How can I speed up the script?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2016-02-17
@2fox

the script hangs due to the end of the timeout (i.e. the curl takes too long to receive a response from the server)
1. mysqli_query($CONNECT, "SELECT * FROM `account`") add LIMIT
2.

mysqli_query($CONNECT, "UPDATE `account` SET `balance` = '$balance[1]' WHERE `id` = '$likes'");
mysqli_query($CONNECT, "UPDATE `account` SET `last` = '$last' WHERE `id` = '$likes'");
mysqli_query($CONNECT, "UPDATE `account` SET `last_work` = 'like' WHERE `id` = '$likes'");

What for 3 requests when all this can be done in 1?

D
Dimonchik, 2016-02-17
@dimonchik2013

1)
multicurl 2) gearman
3) asynchronous PHP

D
DarkMatter, 2016-02-17
@darkmatter

curl spends a lot of time connecting, start likes in small batches of 10 accounts and accurately measure request time, processing time per account. Suddenly at you there indexes do not stand.
They rightly said about trim, the data in the database should already be cleared, although this, of course, is saving on matches ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question