$smcFunc doesn't work after sleep() function

Started by Vladimir Samoilov, April 23, 2016, 02:48:22 AM

Previous topic - Next topic

Vladimir Samoilov

If I call $smcFunc['db_query'] after sleep(5) it works perfectly.
But if I call $smcFunc['db_query'] after sleep(60) it doesn't work with error message "database is busy".

Can anybody explaine how this issue may be resolved?

Thanks.

Arantor

Don't call it with sleep(60), essentially. The database connection drops after a period of time if it is not used, and waiting for a full minute causes it to timeout, as it should.

What are you doing where a full minute of wait is intentional?

Vladimir Samoilov

#2
I am uploading the pictures from smf to some social network using api. So I want to each picture was sending over some time interval (from 1 second to several minutes). And from time to time I am sending query to the database for checking state of this proccess. For example, user can write state "stop" or "pause" to database and I need read this state in the my loop.

I use the following solution

while (.....)
{

sleep(60);

.....some code for upload picture......

if ($needcheck)
{
$request = $smcFunc['db_query']('', '
SELECT state
FROM {db_prefix}spmod_task
WHERE taskid = {int:ti}
LIMIT 1',
array(
'ti' => 0,
)
}

}


Thank you for help.

nend

Have you considered using cron jobs to achieve this?

If it is a function that needs user interaction,  then use Ajax style request.

Also a interesting tidbit, if you go the Ajax route be sure you put the time in there correctly, a week or two ago I missed a extra 0 and flooded SMF with request. I was pleasantly surprised when site wasn't reachable, the forum banned my IP in the flood control table.

Advertisement: