I recently have been using snippets to power a "server status" page for my MinecraftServers, and it was working fine for quite a while, however now for some reason the php code is not updating! (It became very clear when our servers went down, and sadly the server status snippets were not updating, and quite a few of our users were getting confused!)
If I could receive any help, that would be awesome-
Problem:
Php Snippets are not updating (Not even after 24 hours)
Desired Result:
Is there a way to make it update every 2-3 minutes when being used, however if no one goes to the page, not update it at all..?
Snippet Code: on
PasteBin
MODx Version - Revolution 2.2.6-pl
This is most likely due to caching.
Caching in Modx means that the system creates an individual file for each resource in your site. These files are built up by all the snippets, chunks and placeholders you may have in your template and elements being parsed.
If you chose to cache these snippets or chunks, Modx will not call the code again, but just output the content that was generated the very first time the cache was created.
These are cached:
[[mySnippet]]
[[$myChunk]]
These are uncached:
[[!mySnippet]]
[[!$myChunk]]
Please note that you want to use as much caching as possible, but the snippet you are describing (different output without removing the cache) would require uncached tags.
Related
I have a ecommerce store website running with WordPress. I'd like to include a section with a -random custormer's product review, so that every time someone access the page, there will be a different comment there.
I'm not used to PHP, but I managed to create a shortcode which takes a random comment and returns the proper HTML. It is working fine (in eddition mode, every time I insert the shortcode a different comment appears).
My issue is that when I leave the page and return, the previous one is still there. I believe that it is being caused by cache, but I wouldn't like to disable the cache for the whole page.
How you I force the shortcode run again (I don't know if it is the right way to explain) and make sure that at every access, a different comment appears?
One solution I thought is to have JS code which would do preaty much the same thing my PHP code does, using Woocommerce API to get the data. But I'm wondering if there is a simpler solution to do that, like forcing the specific section not being cached or re-run the shortcode.
Thanks!
JS can't do what PHP does here: at most it can create an AJAX-call to the backend that then runs a query for a random comment and returns it. You need to render it thereafter. It's fairly standard, but overkill for your case.
Instead, you're going to want to check whether your caching mechanism supports ESI or something else that excluded parts of your code from being cached.
i wrote a little sh*tcode that loads data from one accounting program in xml format, parses it and adds it to the database, but there is one big problem: the data is displayed on the page itself in CRM, you need to reload the page 2 times, when you first restart the page, the system turns to the cache, and when the second update actually goes to the database, I need somehow using php or js
make it so that it does not access the cache, but access the database
P.S. Version vTigerCRM 7.1 module Products
There are three solution, A) Make dynamic content in your code B) Clear Smarty Cache in your code C) Disable caching in vTiger
If option A works, it is most effective
one is to put a little footer or header in your code that changes the content to let smarty clear cache itself( for example put Date() or a number.
Second solution is to look for SMARTY to clear cache:
// clear the entire cache
$smarty->clearAllCache();
// clears all files over one hour old
$smarty->clearAllCache(3600);
Third
Look for PS_SMARTY_CACHE under Table prefix_configuration and set it to 0
I'm getting a weird issue with including tag. It slows down the page and sometimes kills it. I noted the render time with including tag and without it. See it in the screen shot:
http://prntscr.com/ho1cms http://prntscr.com/ho1boe
It has been working fine for a year, but now suddenly killing pages.
http://prntscr.com/ho1ebb
Since this include tag is mentioning javascript, it is possible that the slow down occurs in javascript context. Could be an asset failing to load in sync or just some very poor code running in sync. That would explain the blank page during loading.
Have you tried to look at how things where going in a browser console or even better browser network audit tool ?
Another thing could be some problems in the included files themselves, but I don't think you will find a reason in the include process itself.
I have an ad network script like the following
http://cdn.domain.com/ad.php?variables=etc
We have about 10,000 hits a second and we are looking at some improvements for our Pseudo code - this is what I have in mind - my question is - would PHP includes slow down my script like the if else codes and would it be worth minifying the PHP on this page:
<?php
// mysql connect
// get variables from publisher
// if publisher has no ads show advertise here banner
// if resolution from variables is 125x125 show that banner or whatever resolution from the vars
// example www.noadhere.com/image/advertishere_{var}125px.jpg
// if publisher has no ads show advertise here banner and also updated mysql with page views for this publisher
// if publisher has a banner then show it and update mysql with page views
// show also the click code that redirects and updates the record with a hit click
?>
I have updated the code. This is the Phase 1 draft for those who are interested. I think it is so much simpler and I am going to minify this - even though there may not be need - we had 4 mysql actions happening. And now there are 3 - I just made the update views a one liner.
# mysql
$c=mysql_connect("sqlmaster.adserver.com","user","************");
mysql_select_db("adserver", $c);
# vars
$a=mysql_real_escape_string($_GET["z"]);//id
$z=mysql_real_escape_string($_GET["z"]);//zone
$h=mysql_real_escape_string($_GET["h"]);//height
$w=mysql_real_escape_string($_GET["w"]);//width
$d=date("Y-m-d H:i:s");//date
$u=mysql_real_escape_string($_SERVER['HTTP_REFERER']);//url
# constructor
# do we have ads?
$r1=mysql_query("");
if(mysql_affected_rows()==0){
# empty ad code unit
echo 'Blog Empty';
} else {
# we have ads - so show random click code
echo 'Click here .php ? and redirect';
}
# update mysql view table for this ad unit - empty or filled
$r2=mysql_query("");
# end constructor
mysql_close($c);
Any suggestions on improving this would be welcomed. I think the mysql_real_escape is slow.
Using include only slows down your script by the amount of time it takes your server to open the file, which is usually just a fraction of a second. So it wouldn't drastically slow down your script execution.
When using a PHP cache, includes really don't matter that much. However, there definitely is a very minor difference.
My own build scripts automatically replace includes with "normal" code, using a self-made syntax that's backwards compatible with PHP:
/*safeinclude*/ include 'file.php';
My parser then reads the PHP file and notices this include. It grabs the contents of the file.php file and replaces the include with this code (after some cleanup, such as removing the leading <?php tag). It then gets saved to the bin directory, which is where the live files are.
This approach works very well, but you must always check for the <?php and ?> tags. Also, you'd have to split src and bin directories, because you can't change anything that's already live anymore.
Your primary focus area for optimizations should probably be the database though, and other CPU-intensive operations such as loops.
There are lots of ways of making code run faster. Usually splitting code into separate files will not improve performance (selectively including just the code you need instead of a huge library will probably help).
You may have noticed that there aren't a lot of off-the shelf solutions for minifying PHP code - there's a good reason for that. It won't make a lot of difference to the execution time (it does for javascript mainly due to the reduction in network transfer time - not in the reduction in parsing time). PHP code doesn't go across the network. And if you want to reduce parsing time, then using an opcode cache is a much effective solution.
Since this is presumably a significant revenue stream, then you should have the skills to know this already. However a lot of performance improvements come about by trial and error (and careful experiment design and measurement) - you might want to invest some time in developing these facilities.
The good thing about running if and else's is that only the code that is needed to be ran will run. Included pages are loaded in a split of a second and do not really make any difference on the speed. Most big websites have long trails of included files and you don't really notice it.
I am honestly not sure where the issue lays but here is my problem:
I have a single file: card.gif. When I check firebug or Google pagespeed, I learn the file is called twice during the page fetch once as normal file name and a second time with a random number (that does not change). Example:
card.gif
card.gif?1316720450953
I have scoured my actual source code, the image is only called once. It is not called in a CSS file. To be honest I have no idea what is the issue, some thought that when I originally installed mod_pagespeed that it appended ID's to each image in cache for any future overwrites but I can't be certain.
Has anybody ever had this issue before?
In the end - Dagon's comments above led me to believe that things like Firebug and Pagespeed may not always be correct. I do show two images being loaded in the timelines for both plugins but it is very difficult for me to decifer otherwise. If another answer is provided contradicting this, I am more than happy to test that theory.