I am seeing inconsistent behavior from modx with my snippets. To debug my snippets I started creating regression testing scripts that run my snippets using the API. Through this I've discovered that the login snippet is misbehaving as well. Here is a sample of code I'm using:
define('MODX_CORE_PATH', '/path/to/core/');
define('MODX_CONFIG_KEY', 'config');
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx -> setDebug(TRUE);
$modx -> initialize('web');
$modx->getService('error','error.modError');
$response = $modx->runProcessor('security/login', array( 'username'=>'someuser','password'=>'pw'));
$output = $modx->runSnippet('mysnippet', array('key'=>'value'));
Pretty standard, right? This code works, but not always. When the code is unsuccessful, $modx->user->get('username') shows '(anonymous)' as the user (id=0); my snippets just don't work. If I log the user in or out on the website, my api script works fine for a while but then stops working (until I log in or out again).
I'm not seeing much of a pattern in what I'm doing that would trigger the failure. I can run the script 3 times without changing anything and it will suddenly not work on the 4th time. I rarely get it to work past about 5 runs, it always works at least once after logging in or out.
Very odd behavior. Any ideas why this might be happening?
Edit: I should point out that my snippets occasionally stop working on the website. That was the reason for building the regression test scripts.
Edit: Logging in on the website side of things seems to be working all the time. My snippets, however, don't work on website at times. My thought process is that if I can pin down what is happening in my testing scripts using the modx api, I will be able to address the issues on the website.
[ed. note: shanderson last edited this post 10 years, 3 months ago.]