ModX Revo
I form a big picture of hundreds of small, avatar users (to optimize the page load time - one picture weighing 100kB or 400 of 2kB is loaded - there is some difference)))

The request is banal and without incoming parameters select img_id from table where val=20 , get a sample img_id (this is the unicid name of small pictures).
Connection to the database is standard for the ModX snippet via $query = $modx->query($sql);

Then in the cycle through the GD-functions imagecreate, imagecopy, imagepng form one image
In my youth I made a code for generating a picture in the form of a snippet, I call the snippet in the template, the template is respectively linked to a specific page, the page is called via cron. I found by experience that the script runs for 15-20 seconds, while the query in the database is 0.05 seconds, the rest is PHP and probably adds something ModX itself.
I tried to issue as a separate php file with a connection to the database as in the good old days by specifying passwords inside the file, while I see that the final file is updated within a second (stupidly by the time the file changes to ftp). ModX, Carl?
What is the best way to do now, in order, as they say, to eat a fish and not get on a fence from stakes?))) Ie connect to the database without explicitly specifying passwords in the file and at the same time dispense with the bizarre API ModX. Run the specified code inside the snippet will probably have to be deleted.

Closed due to the fact that it is necessary to reformulate the question so that it is possible to give an objectively correct answer by the participants aleksandr barakin , cheops , HamSter , Denis , user207618 Oct 7 '16 at 6:46 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    To load the modX environment , just run:

     require_once '/absolute/path/to/modx/config.core.php'; require_once MODX_CORE_PATH.'model/modx/modx.class.php'; $modx = new modX(); 

    And, then you can call $modx->query()

    See https://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/loading-modx-externally

    • the link all three methods did not start, now I'll try yours. But in the end, is the API still loading? I basically need a custom table, which is simply inserted into the engine database, nothing binds them anymore - Sergey V.
    • one
      @ SergeyV. You correctly specify the path in the first require_once ? Any errors in the logs there? - tutankhamun pm
    • one
      @ SergeyV. Now "measured". These lines are executed in about 30ms and eats off about 2.5 MB of memory. How critical is this for you? (and not all is loaded) - tutankhamun
    • 30ms? it is great! I will hammer all the way to still run, I really like this method! at the same time, I’ll check that it loads in my version .... I put the path in the first require_once, it seems to be correct (4th nesting level), since cron says that it’s done successfully, maybe it also depends on WHERE my file is is lying? in theory should not depend. By the way, where is it safer to add such files so that no one will run their self-indulgence for the sake of? Now the file is in the assets / components / mysupercomponent folder - Sergey V.
    • @SergeyW By the way, I copied the lines from this article, but actually the file is relative to the root modX core / config / config.inc.php . Make sure that the first line contains the absolute path to it - tutankhamun