Skip to Content Skip to Menu

PHP's memory_limit issue in plug_cbpaidsubscriptions

  • maxkrylov
  • maxkrylov
  • ONLINE
  • Posts: 7
  • Thanks: 0
  • Karma: 0
1 day 18 hours ago #343649 by maxkrylov
Hi Krileon,

I'd like to report a bug in CB Paid Subscriptions affecting Joomla 5.4.4.

The following two files unconditionally override PHP's memory_limit to 48M at runtime:

- components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/cbpaidsubscriptions.php
- components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/cbpaidsubscriptions.sysplug.php

Both contain:
@ini_set('memory_limit', '48M');

The problem is that this line executes regardless of the server's current memory_limit setting. In my case, the server is configured at 1024M, but CB Paid Subscriptions overrides it down to 48M globally, affecting all components loaded after it — including OSMap, which then crashes with a fatal memory exhausted error on the frontend.

The fix I applied as a workaround was to replace 48M with 256M in both files, which resolved the issue immediately.

The correct fix would be to only increase the memory limit if it is currently below the required threshold, never decrease it:

if (ini_get('memory_limit') !== '-1' && 
    (int)ini_get('memory_limit') < 48) {
    @ini_set('memory_limit', '48M');
}

This would ensure CB Paid Subscriptions gets the memory it needs without silently breaking other components on the site.

Environment:
- Joomla 5.4.4
- CB Paid Subscriptions (latest version)
- PHP memory_limit on server: 1024M

Thanks for looking into this!
Best regards.
Max.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 50311
  • Thanks: 8616
  • Karma: 1472
1 day 16 hours ago #343656 by krileon
The memory limit set is only applied if the current memory limit is too low. Notice the entire block is surrounded by an IF condition checking if memory limit is less than 48. So if that's being applied I suspect your memory limit isn't properly being set by php.ini. Please provide exactly what you have set in php.ini (e.g. "memory_limit = 512M").


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • maxkrylov
  • maxkrylov
  • ONLINE
  • Posts: 7
  • Thanks: 0
  • Karma: 0
1 day 16 hours ago - 1 day 16 hours ago #343659 by maxkrylov
Hi and thanks for the answer.The
Code:
phpinfo_test.php
confirms PHP is receiving
Code:
memory_limit = 1024M
at runtime (
Code:
ini_get('memory_limit')
returns
Code:
1024M
). There is no
Code:
php.ini
or
Code:
.user.ini
in
Code:
/public_html/
. The limit is set via cPanel's PHP Selector (CloudLinux/Ex2 shared hosting).

 

Despite this, the fatal error consistently reports
Code:
50331648 bytes
(= 48M). The issue was resolved by modifying the
Code:
@ini_set('memory_limit', '48M')
line in both:
  • Code:
    cbpaidsubscriptions.php
  • Code:
    cbpaidsubscriptions.sysplug.php
If the
Code:
ini_set
is truly conditional (only applied when current limit < 48M), then it should never have triggered on our server. Could there be a case where the condition evaluates incorrectly, for example due to how
Code:
ini_get()
returns the value as a string (
Code:
"1024M"
) rather than an integer, causing the comparison to fail?
Last edit: 1 day 16 hours ago by maxkrylov.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 50311
  • Thanks: 8616
  • Karma: 1472
1 day 15 hours ago #343662 by krileon
It's processed into an integer and I've confirmed on 3 different installs with 3 different PHP versions it's working fine. $memMax would be the calculated bytes from whatever memory_limit is set to. You can var_dump that entire chain and see what CBSubs is seeing at the top of your page. I've no idea why this isn't working for your install in particular.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • maxkrylov
  • maxkrylov
  • ONLINE
  • Posts: 7
  • Thanks: 0
  • Karma: 0
1 day 15 hours ago - 1 day 15 hours ago #343663 by maxkrylov
var_dump confirms the chain works correctly on our install: memory_limit = "1024M", converted to 1073741824 bytes, condition < 50331648 evaluates to false.

So ini_set should never have triggered. We suspect a plugin load order issue where CBSubs was initializing before PHP's memory limit was properly set by the server. The fix (replacing 48M with 256M) resolved the issue. We'll monitor if it recurs.

We are under PHP 8.3, Joomla 5.4.4 and CB 2.11.0. OSMap has crashed with:

Fatal error: Allowed memory size of 50331648 bytes exhausted (tried to allocate 4096 bytes)
Fatal error: Allowed memory size of 50331648 bytes exhausted (tried to allocate 20480 bytes)

Fatal error: Allowed memory size of 50331648 bytes exhausted (tried to allocate 20480 bytes)
PHP Request Shutdown: Cannot call session save handler in a recursive manner in Unknown on line 0

Fixing the 
memory_limit to 48M in:

- components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/cbpaidsubscriptions.php
- components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/cbpaidsubscriptions.sysplug.php

Solved the problem. No other issues have been observed.
Last edit: 1 day 15 hours ago by maxkrylov.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 50311
  • Thanks: 8616
  • Karma: 1472
1 day 14 hours ago #343664 by krileon
Your solution earlier that fixed your problem was to add "ini_get('memory_limit') !== '-1'" to the IF condition. My guess is OSMap is setting memory_limit to -1 and is the root of your issue. -1 removes memory limits, but that's an incredibly bad idea for an extension to be doing. Will add a bug ticket to check for -1, but I would recommend bringing this up to OSMap. They should be checking for and setting a minimum like CBSubs does not setting the limit to unlimited as that's a fast track way to take down someone's server.

forge.joomlapolis.com/issues/9836


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: maxkrylov

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum