Yii Framework Forum

Action called twice only in debug mode


(mazengh) #1

I have an action that reads from files, then inserts rows into a database table and after that redirects to a index of model (index.php?r=punch)

when I try to run the action by entering the url in the browser (index.php?r=punch/read-files), data is read from the files and inserted into db correctly, but the same action is running again which generates duplicates in the database. I have noticed that when I comment the below lines, which is disabling debug mode, my code works as expected inserting the rows just once. But I really need debug mode to work properly… any ideas?

//defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, true);
//defined(‘YII_ENV’) or define(‘YII_ENV’, ‘dev’);


(Alexander Makarov) #2

Can you try disabling debug extension without disabling debug mode and switching to production environment?


(mazengh) #3

I commented the below in web.php

// configuration adjustments for ‘dev’ environment
//$config[‘bootstrap’][] = ‘debug’;
//$config[‘modules’][‘debug’] = [
//‘class’ => ‘yii\debug\Module’,
// uncomment the following to add your IP if you are not connecting from localhost.
//‘allowedIPs’ => [‘127.0.0.1’, ‘::1’, ‘192.168.166.72’],
//];

and removed the below comments in index.php

// comment out the following two lines when deployed to production
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, true);
defined(‘YII_ENV’) or define(‘YII_ENV’, ‘dev’);

this works (meaning no double calls) but with no debug toolbar


(mazengh) #4

Anyone having the same issue?


(Alexander Makarov) #5

Don’t do this part. I’ve asked for disabling debug toolbar but not disabling debug mode.


(Adinugro) #6

I did, but its bit weird. If I use my fiber optic connection, I occasionally get my actions (create/update/delete) fired twice. the second one will produce an error since the row is added/changed/deleted already.

However, when I switched to other provider or using 4G connection, I did not encounter this problem.

Yes, I have debugging toolbar active and still in debug mode, not production mode. Do these have any effects?


(Alexander Makarov) #7

It sounds like something is requesting page twice and since when debug toolbar is disabled there’s no such behavior it sounds like a bug in debug toolbar. Still, it’s very strange that it wasn’t reported by anyone so either it’s environment specific or very hard to reproduce. Anyway, without a way to reproduce it we can’t fix it…


(mazengh) #8

Other people already encountered this issue before, that’s how I knew it was the debug toolbar. Check the link below

In my environment I can reproduce it every time. It’s a LAN application, not on the WWW. I will try just commenting the below and report again.

defined(‘YII_ENV’) or define(‘YII_ENV’, ‘dev’);


(Adinugro) #9

I got it again this morning. It called twice when delete when debug toolbar was not allowed (IP was not put on the list when called twice). But I think debug toolbar was active?

FYI, I used yii2-ajaxcrud extension, and the call was ajax call not pjax call.

The thing is this was happened when I used my fiber optic connection. It worked fine using 4G connection. This is the some piece of code on the same server access from the same computer.


(mazengh) #10

The below configuration does not result in double calls.

commented the below web.php

// configuration adjustments for ‘dev’ environment
//$config[‘bootstrap’][] = ‘debug’;
//$config[‘modules’][‘debug’] = [
//‘class’ => ‘yii\debug\Module’,
// uncomment the following to add your IP if you are not connecting from localhost.
//‘allowedIPs’ => [‘127.0.0.1’, ‘::1’, ‘192.168.166.72’],
//];

debug mode is enabled in index.php

// comment out the following two lines when deployed to production
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, true);
defined(‘YII_ENV’) or define(‘YII_ENV’, ‘dev’);

this works (meaning no double calls) but with no debug toolbar

P.S.: I can reproduce the bug any time


(Alexander Makarov) #11

Can you reproduce it without yii2-ajaxcrud?


(Adinugro) #12

I dont have any problem without yii2-ajaxcrud. Even, the weird thing is that, when the it is in the index action, I have no problem. The problem was come up when the gridview is put on the view action. In my example, I have Header with Details.In header/index no problem. however ini header/view where I put detailview of header and gridview of details. The ajax calls are twice only when I used fiber optic connection. 4g connection to the same code will have no problems.

I am thinking that if it is slow connection, it will fail and call twice. but it is ajax call not pjax call…


(Alexander Makarov) #13

That’s likely a problem in yii2-ajaxcrud. Worth checking with the author of that extension.