MyBB Community Forums

Full Version: When cURL connection is lost, whole site goes down?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I just noticed a severe fault in my MyXBL plugin that uses CURL to fetch stats. basically, if te XML fee can't be parsed for whatever reason (eg: the site is down), the whole forum refuses to load.

I take it that this problem is caused because I initialize the connection in the global_start hook, but I just want confirmation. I think I know how to fix it, but I just want to confirm that this would cause the error.
Normally you can add a timeout to curl.

http://php.net/manual/en/book.curl.php

CURLOPT_TIMEOUT

You'll have to find the code for the curl settings and add that properly. Maybe set it for 10 seconds or whatever you're comfortable with.
Ah, I did have that larocca, but I obviously deleted it when I rewrote the plugin to use caching. Lock this please somebody - stupid error that labrocca has helped fix ;D

EDIT: That didn't seem to help...
PHP isn't multithreaded, so if you do something in global_start that blocks, sure it will block loading the rest of the page. It's best not to rely on third party sites during a page load because even if it does not time out, it will drastically add to the delay of the page loading process.

Better to retrieve, and cache, the necessary information independently, and only use the cache during page loads. For example with MyBB you could have a task that updates the info cache every so often. The tasks run in a separate request in the background, not disturbing the page load process.
(2010-11-02, 12:50 AM)frostschutz Wrote: [ -> ]PHP isn't multithreaded, so if you do something in global_start that blocks, sure it will block loading the rest of the page. It's best not to rely on third party sites during a page load because even if it does not time out, it will drastically add to the delay of the page loading process.

Better to retrieve, and cache, the necessary information independently, and only use the cache during page loads. For example with MyBB you could have a task that updates the info cache every so often. The tasks run in a separate request in the background, not disturbing the page load process.

Cheers frostschutz. ATM, I only grab the stats for the currently logged in user at the global_start hook (rather than all of them) in an effort to speed things up, but I never actually thought about using a task.

I'll have to look into how it's done though - I take it it isn't as easy as just changing the hook location?