Some fatal errors

Kirk

Well-known member
Hey all so recently I got some bugs reported on one of my add-ons

So here are some of the errors some of the users have been reporting to me

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\forum\library\XenForo\Image\Gd.php on line 78

Fatal error: Maximum execution time of 190 seconds exceeded in C:\xampp\htdocs\forum\library\XenForo\Image\Gd.php on line 78

ErrorException: Fatal Error: Maximum execution time of 120 seconds exceeded - library/XenForo/Image/Gd.php:186
Generated By: Unknown Account, Today at 5:43 PM
Stack Trace
#0 [internal function]: XenForo_Application::handleFatalError()
#1 {main}
Request State
array(3) {
["url"] => string(58) "xxx.net"
["_GET"] => array(1) {
["register/register"] => string(0) ""
}
["_POST"] => array(16) {
["username"] => string(0) ""
["c9b27263b9a83d84101f7a221377022d"] => string(12) "xxx"
["avatar_upload"] => string(1) "0"
["340212248c47f964cde9e0393704fc8a"] => string(0) ""
["96cf24fadb584241b76e6b838e8dc20b"] => string(21) "xxx@gmail.com"
["password"] => string(8) "********"
["fc5796452a9baf6c479bc5b4c9fb9fb5"] => string(6) "female"
["dob_month"] => string(2) "12"
["dob_day"] => string(2) "23"
["dob_year"] => string(4) "1989"
["location"] => string(14) "hetton le hole"
["7d25ef349dbb075e80865050802b0836"] => string(13) "Europe/London"
["g-recaptcha-response"] => string(420) ["agree"] => string(1) "1"
["_xfToken"] => string(8) "********"
}
}


And here's my DataWriter code:
PHP:
class GFNRegAvatar_Extend_XenForo_DataWriter_User extends XFCP_GFNRegAvatar_Extend_XenForo_DataWriter_User
{
    protected $_avatarFile = false;

    protected function _preSave()
    {
        parent::_preSave();

        if (!XenForo_Application::isRegistered('regAvatarProxy'))
        {
            return;
        }

        $avatar = XenForo_Application::get('regAvatarProxy');
        if (empty($avatar['file']))
        {
            if ($avatar['required'] && $avatar['supported'])
            {
                $this->error(new XenForo_Phrase('gfnregavatar_please_select_valid_avatar'), 'avatar');
            }

            return;
        }

        /** @var XenForo_Upload $file */
        $file = $avatar['file'];

        if (!$file->isValid())
        {
            foreach ($file->getErrors() as $error)
            {
                $this->error($error, 'avatar');
            }
        }

        if (!$file->isImage())
        {
            $this->error(new XenForo_Phrase('uploaded_file_is_not_valid_image'), 'avatar');
        }

        $imageType = $file->getImageInfoField('type');
        if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))
        {
            $this->error(new XenForo_Phrase('uploaded_file_is_not_valid_image'), 'avatar');
        }

        $this->_avatarFile = $file->getTempFile();
    }

    protected function _postSaveAfterTransaction()
    {
        parent::_postSaveAfterTransaction();

        if ($this->_avatarFile)
        {
            /** @var XenForo_Model_Avatar $avatarModel */
            $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');

            try
            {
                $avatarModel->applyAvatar($this->get('user_id'), $this->_avatarFile);
            }
            catch (Exception $e)
            {
                XenForo_Error::logException($e);
            }
        }
    }
}
 
Oh my i should of been thorough detailed in my original post.

Anyways So when people upload a large avatar like 500px by 500px or 1000px by 1000px this is when the error occurs. I feel like it's somewhere in my DW code that's causing this problem.
 
I tried uploading a 1000px by 1000px as an avatar and no errors occur when I do this when i have my add-on disabled.
 
So you would look for $avatarModel->applyAvatar($this->get('user_id'), $this->_avatarFile);
 
So you would look for $avatarModel->applyAvatar($this->get('user_id'), $this->_avatarFile);
Right which I have in my protected function _postSaveAfterTransaction

PHP:

class GFNRegAvatar_Extend_XenForo_DataWriter_User extends XFCP_GFNRegAvatar_Extend_XenForo_DataWriter_User
{
protected $_avatarFile = false;

protected function _preSave()
{
parent::_preSave();

if (!XenForo_Application::isRegistered('regAvatarProxy'))
{
return;
}

$avatar = XenForo_Application::get('regAvatarProxy');
if (empty($avatar['file']))
{
if ($avatar['required'] && $avatar['supported'])
{
$this->error(new XenForo_Phrase('gfnregavatar_please_select_valid_avatar'), 'avatar');
}

return;
}

/** @var XenForo_Upload $file */
$file = $avatar['file'];

if (!$file->isValid())
{
foreach ($file->getErrors() as $error)
{
$this->error($error, 'avatar');
}
}

if (!$file->isImage())
{
$this->error(new XenForo_Phrase('uploaded_file_is_not_valid_image'), 'avatar');
}

$imageType = $file->getImageInfoField('type');
if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))
{
$this->error(new XenForo_Phrase('uploaded_file_is_not_valid_image'), 'avatar');
}

$this->_avatarFile = $file->getTempFile();
}

protected function _postSaveAfterTransaction()
{
parent::_postSaveAfterTransaction();

if ($this->_avatarFile)
{
/** @var XenForo_Model_Avatar $avatarModel */
$avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');

try
{
$avatarModel->applyAvatar($this->get('user_id'), $this->_avatarFile);
}
catch (Exception $e)
{
XenForo_Error::logException($e);
}
}
}
}
(I've marked in red). So would I need to move the $avatarModel->applyAvatar($this->get('user_id'), $this->_avatarFile); into _preSave function?
 
Last edited:
I think it does not matter where you call this function, this function takes a long time anywhere where you execute it.

It's possible that your server has some problems uploading a file, or there are other issues. I would first take a look if really this function is slowing down anything. If yes, I would take a good look at this function, how it works, what it does.
 
So I tried commentating out that line and it went very fast but the avatar didn't show after registration so I guess I need to dig into that line of code more to understand it
 
From what I see the applyAvatar() grabs the user id, the image width and height and the time stamp. If I'm wrong on this could someone give a better explanation of what the applyAvatar() does?
 
I have actually no idea how this function works, I just would look at the red part: $avatarModel->applyAvatar($this->get('user_id'), $this->_avatarFile);It's possible that the file is very large and the function has some problems working with this large data.
 
Top Bottom