Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch files (after callback) => high php memory requirements #30

Closed
medienverbinder opened this issue Jan 10, 2016 · 6 comments
Closed

Comments

@medienverbinder
Copy link
Contributor

Using the "E2Ehelper.php" class (threema-msgapi-sdk-php/source/Threema/MsgApi/Helpers/E2EHelper.php) I receive image and file messages via callback URL.

Sending an exemplary image (about 1 MB) through "image dialog" on my smartphone to the gateway account can be received untainted by the helper class E2EHelper.php. However, the same image needs a larger php memory allocation via the "file dialog", and often leads to the following annoying error.

PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in "composer/rugk/threema-msgapi-sdk-php/source/Salt/FieldElement.php" on line 66

Has anyone else problems with the reception of the messages and possibly propose a solution?

( but I do not mean an increase in the memory ... ;-) )

Best Regards

@rugk
Copy link
Owner

rugk commented Jan 10, 2016

Do you probably have some small wrapper code for receiving file messages so that it can be reproduced easily?

@medienverbinder
Copy link
Contributor Author

I use the official version of the Threema SDK. The structure is the same for all supported message types:

...

$e2eHelper = new E2EHelper(hex2bin($threema_privatekey), $threema_connector);

try {
    $message = $e2eHelper->receiveMessage(
      $threema_id_sender,
      $threema_message_id,
      hex2bin($threema_box),
      hex2bin($threema_nonce),
      $threema_private_folder_uri
    );

    return $message;
}
catch (Exception $exception) {
    watchdog('threema:', 'Error: %errmsg', array('%errmsg' => $exception), WATCHDOG_ERROR);
    return false;
}

...



...

if($message->isSuccess()) {

  $threema_message = $message->getThreemaMessage();

}

...

The handling of the message is processed by "public final function receiveMessage" within the "E2EHelper" class. (https://github.com/rugk/threema-msgapi-sdk-php/blob/official/source/Threema/MsgApi/Helpers/E2EHelper.php)

My initial php configuration worked with 128 MB memory size receiving an exemplary image (about 1 MB) through "image dialog".

Same image needs about > 300 MB php memory size receiving through the "file dialog".

@rugk
Copy link
Owner

rugk commented Jan 11, 2016

Mind that Threema clients usually compress images before sending, but this obviously should not make the image larger.
Did you already contacted Threema about this issue?

@medienverbinder
Copy link
Contributor Author

I have sent a message to the Threema support.
Here are the results when processing an image of approximately 1 MB:

(message instanceof ImageMessage)
225 11/Jan 21:50 notice threema Peak of memory usage: 115.75 MB.

(message instanceof FileMessage)
233 11/Jan 21:51 notice threema Peak of memory usage: 291.50 MB.

@medienverbinder
Copy link
Contributor Author

With the libsodium library installed the PHP memory requirements are much lower.

Sending an exemplary image (about 1 MB) through "image dialog":

 308  16/Jan 12:33  notice    threema  Peak of memory usage: 14.25 MB.

Sending an exemplary image (about 1 MB) through "file dialog":

 317  16/Jan 12:33  notice    threema  Peak of memory usage: 16.25 MB.

For me this is now O.K.

@rugk
Copy link
Owner

rugk commented Jan 16, 2016

Yeah, the php implementation is quite resource-intensive and buggy.
Personally I would not mind if it would be removed completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants