Bulk delete operation occurs Internal Server Error in Yii2












5















I have bulk delete operation in Yii2, following is the code snipped to delete the records with activity log (Here DBMS is PostgreSQL)-



$companies = Yii::$app->request->post('ids', '');
if($companies && count($companies)) {
foreach ($companies as $company) {
try{
$utsendelseid = $company['utsendelseid'];
$mailid = $company['mailid'];

$model = MailSend::find()->where(['utsendelseid' => $utsendelseid, 'mailid' => $mailid])->one();

if($model && !$model->mailsendt) {
if($model->delete()) {
// if model deleted successfully then keep a log using commandBus
$companyModel = $this->findCompanyModel($model->kundenr);
$questionnaireModel = $this->findModel($utsendelseid);

Yii::$app->commandBus->handle(new AddCompanyLogCommand([
'kundenr' => $model->kundenr,
'portal_id' => ($questionnaireModel?$questionnaireModel->prosjektkode:''),
'activity' => Yii::t('backend', 'Slettet fra spørreskjema'),
'notes' => Yii::t('backend', 'Company "{company}" has been deleted from questionnaire - "{questionnaire}"("{questionnaire_id}")', [
'company' => ($companyModel?$companyModel->etternavn:''),
'questionnaire' => ($questionnaireModel?$questionnaireModel->beskrivelse:''),
'questionnaire_id' => $utsendelseid
]),
'activity_type_code' => 30,
]));
}
}
}
// even tried with PDOException
catch(Exception $e){
echo $e->getMessage();
// exit the request processing here
exit(0);
}
}
}


This works fine if the number of records need to be deleted is below 300. I am getting Internal Server Error if the number of records above 300 even the code is inside try{}catch() block. I set max execution time to -1, and max memory allocation to 5120M which is not the issue for now. I thought it's a problem of too many connections error while have that much SQL operations, thus, I enable persistent connection in Yii2 by putting 'attributes'=> [PDO::ATTR_PERSISTENT => true]. But problem is still there.



Here, query is executed upto 45 seconds and error occured there. With in 45 seconds it delete upto 300 records and keep log of them. After that it gives Internal Server Error. There is no error in query. Ok, I wrote custom query to speed up and that deletes upto 500 records. But need to face same problem while having more than 500 records.



My questions are -




  1. Why I am getting Internal Server Error even though code is inside try{}catch() block?


  2. Why it works upto 45 seconds?


  3. Is that a case of sub-process killing by Apache?


  4. Is it a problem of max time allowed to run a query?


  5. If this case is of too many connections then why the problem occurred with persistent connection?



Thanks in advance.










share|improve this question




















  • 3





    the error logs would have more precise details about the error , Internal Server Error can be anything.

    – Muhammad Omer Aslam
    Nov 27 '18 at 7:44






  • 2





    Seems that u have display_errors=off and execution timeout. Check web server error log and under runtime/logs.

    – SiZE
    Nov 28 '18 at 5:28











  • @SiZE debug mode is true in yii2, and max time execution is 0 - that means no limit to execution time.

    – Veshraj Joshi
    Nov 28 '18 at 6:11













  • @VeshrajJoshi 500 means something goes wrong with ur server and error_reporting, display_errors or display_startup_errors are off. Param debug set to true can not guaranty that. Then what about server error logs? Why u cant just read them?

    – SiZE
    Nov 29 '18 at 15:19


















5















I have bulk delete operation in Yii2, following is the code snipped to delete the records with activity log (Here DBMS is PostgreSQL)-



$companies = Yii::$app->request->post('ids', '');
if($companies && count($companies)) {
foreach ($companies as $company) {
try{
$utsendelseid = $company['utsendelseid'];
$mailid = $company['mailid'];

$model = MailSend::find()->where(['utsendelseid' => $utsendelseid, 'mailid' => $mailid])->one();

if($model && !$model->mailsendt) {
if($model->delete()) {
// if model deleted successfully then keep a log using commandBus
$companyModel = $this->findCompanyModel($model->kundenr);
$questionnaireModel = $this->findModel($utsendelseid);

Yii::$app->commandBus->handle(new AddCompanyLogCommand([
'kundenr' => $model->kundenr,
'portal_id' => ($questionnaireModel?$questionnaireModel->prosjektkode:''),
'activity' => Yii::t('backend', 'Slettet fra spørreskjema'),
'notes' => Yii::t('backend', 'Company "{company}" has been deleted from questionnaire - "{questionnaire}"("{questionnaire_id}")', [
'company' => ($companyModel?$companyModel->etternavn:''),
'questionnaire' => ($questionnaireModel?$questionnaireModel->beskrivelse:''),
'questionnaire_id' => $utsendelseid
]),
'activity_type_code' => 30,
]));
}
}
}
// even tried with PDOException
catch(Exception $e){
echo $e->getMessage();
// exit the request processing here
exit(0);
}
}
}


This works fine if the number of records need to be deleted is below 300. I am getting Internal Server Error if the number of records above 300 even the code is inside try{}catch() block. I set max execution time to -1, and max memory allocation to 5120M which is not the issue for now. I thought it's a problem of too many connections error while have that much SQL operations, thus, I enable persistent connection in Yii2 by putting 'attributes'=> [PDO::ATTR_PERSISTENT => true]. But problem is still there.



Here, query is executed upto 45 seconds and error occured there. With in 45 seconds it delete upto 300 records and keep log of them. After that it gives Internal Server Error. There is no error in query. Ok, I wrote custom query to speed up and that deletes upto 500 records. But need to face same problem while having more than 500 records.



My questions are -




  1. Why I am getting Internal Server Error even though code is inside try{}catch() block?


  2. Why it works upto 45 seconds?


  3. Is that a case of sub-process killing by Apache?


  4. Is it a problem of max time allowed to run a query?


  5. If this case is of too many connections then why the problem occurred with persistent connection?



Thanks in advance.










share|improve this question




















  • 3





    the error logs would have more precise details about the error , Internal Server Error can be anything.

    – Muhammad Omer Aslam
    Nov 27 '18 at 7:44






  • 2





    Seems that u have display_errors=off and execution timeout. Check web server error log and under runtime/logs.

    – SiZE
    Nov 28 '18 at 5:28











  • @SiZE debug mode is true in yii2, and max time execution is 0 - that means no limit to execution time.

    – Veshraj Joshi
    Nov 28 '18 at 6:11













  • @VeshrajJoshi 500 means something goes wrong with ur server and error_reporting, display_errors or display_startup_errors are off. Param debug set to true can not guaranty that. Then what about server error logs? Why u cant just read them?

    – SiZE
    Nov 29 '18 at 15:19
















5












5








5








I have bulk delete operation in Yii2, following is the code snipped to delete the records with activity log (Here DBMS is PostgreSQL)-



$companies = Yii::$app->request->post('ids', '');
if($companies && count($companies)) {
foreach ($companies as $company) {
try{
$utsendelseid = $company['utsendelseid'];
$mailid = $company['mailid'];

$model = MailSend::find()->where(['utsendelseid' => $utsendelseid, 'mailid' => $mailid])->one();

if($model && !$model->mailsendt) {
if($model->delete()) {
// if model deleted successfully then keep a log using commandBus
$companyModel = $this->findCompanyModel($model->kundenr);
$questionnaireModel = $this->findModel($utsendelseid);

Yii::$app->commandBus->handle(new AddCompanyLogCommand([
'kundenr' => $model->kundenr,
'portal_id' => ($questionnaireModel?$questionnaireModel->prosjektkode:''),
'activity' => Yii::t('backend', 'Slettet fra spørreskjema'),
'notes' => Yii::t('backend', 'Company "{company}" has been deleted from questionnaire - "{questionnaire}"("{questionnaire_id}")', [
'company' => ($companyModel?$companyModel->etternavn:''),
'questionnaire' => ($questionnaireModel?$questionnaireModel->beskrivelse:''),
'questionnaire_id' => $utsendelseid
]),
'activity_type_code' => 30,
]));
}
}
}
// even tried with PDOException
catch(Exception $e){
echo $e->getMessage();
// exit the request processing here
exit(0);
}
}
}


This works fine if the number of records need to be deleted is below 300. I am getting Internal Server Error if the number of records above 300 even the code is inside try{}catch() block. I set max execution time to -1, and max memory allocation to 5120M which is not the issue for now. I thought it's a problem of too many connections error while have that much SQL operations, thus, I enable persistent connection in Yii2 by putting 'attributes'=> [PDO::ATTR_PERSISTENT => true]. But problem is still there.



Here, query is executed upto 45 seconds and error occured there. With in 45 seconds it delete upto 300 records and keep log of them. After that it gives Internal Server Error. There is no error in query. Ok, I wrote custom query to speed up and that deletes upto 500 records. But need to face same problem while having more than 500 records.



My questions are -




  1. Why I am getting Internal Server Error even though code is inside try{}catch() block?


  2. Why it works upto 45 seconds?


  3. Is that a case of sub-process killing by Apache?


  4. Is it a problem of max time allowed to run a query?


  5. If this case is of too many connections then why the problem occurred with persistent connection?



Thanks in advance.










share|improve this question
















I have bulk delete operation in Yii2, following is the code snipped to delete the records with activity log (Here DBMS is PostgreSQL)-



$companies = Yii::$app->request->post('ids', '');
if($companies && count($companies)) {
foreach ($companies as $company) {
try{
$utsendelseid = $company['utsendelseid'];
$mailid = $company['mailid'];

$model = MailSend::find()->where(['utsendelseid' => $utsendelseid, 'mailid' => $mailid])->one();

if($model && !$model->mailsendt) {
if($model->delete()) {
// if model deleted successfully then keep a log using commandBus
$companyModel = $this->findCompanyModel($model->kundenr);
$questionnaireModel = $this->findModel($utsendelseid);

Yii::$app->commandBus->handle(new AddCompanyLogCommand([
'kundenr' => $model->kundenr,
'portal_id' => ($questionnaireModel?$questionnaireModel->prosjektkode:''),
'activity' => Yii::t('backend', 'Slettet fra spørreskjema'),
'notes' => Yii::t('backend', 'Company "{company}" has been deleted from questionnaire - "{questionnaire}"("{questionnaire_id}")', [
'company' => ($companyModel?$companyModel->etternavn:''),
'questionnaire' => ($questionnaireModel?$questionnaireModel->beskrivelse:''),
'questionnaire_id' => $utsendelseid
]),
'activity_type_code' => 30,
]));
}
}
}
// even tried with PDOException
catch(Exception $e){
echo $e->getMessage();
// exit the request processing here
exit(0);
}
}
}


This works fine if the number of records need to be deleted is below 300. I am getting Internal Server Error if the number of records above 300 even the code is inside try{}catch() block. I set max execution time to -1, and max memory allocation to 5120M which is not the issue for now. I thought it's a problem of too many connections error while have that much SQL operations, thus, I enable persistent connection in Yii2 by putting 'attributes'=> [PDO::ATTR_PERSISTENT => true]. But problem is still there.



Here, query is executed upto 45 seconds and error occured there. With in 45 seconds it delete upto 300 records and keep log of them. After that it gives Internal Server Error. There is no error in query. Ok, I wrote custom query to speed up and that deletes upto 500 records. But need to face same problem while having more than 500 records.



My questions are -




  1. Why I am getting Internal Server Error even though code is inside try{}catch() block?


  2. Why it works upto 45 seconds?


  3. Is that a case of sub-process killing by Apache?


  4. Is it a problem of max time allowed to run a query?


  5. If this case is of too many connections then why the problem occurred with persistent connection?



Thanks in advance.







php postgresql yii2 internal-server-error






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 6:41







Veshraj Joshi

















asked Nov 27 '18 at 6:31









Veshraj JoshiVeshraj Joshi

2,0952921




2,0952921








  • 3





    the error logs would have more precise details about the error , Internal Server Error can be anything.

    – Muhammad Omer Aslam
    Nov 27 '18 at 7:44






  • 2





    Seems that u have display_errors=off and execution timeout. Check web server error log and under runtime/logs.

    – SiZE
    Nov 28 '18 at 5:28











  • @SiZE debug mode is true in yii2, and max time execution is 0 - that means no limit to execution time.

    – Veshraj Joshi
    Nov 28 '18 at 6:11













  • @VeshrajJoshi 500 means something goes wrong with ur server and error_reporting, display_errors or display_startup_errors are off. Param debug set to true can not guaranty that. Then what about server error logs? Why u cant just read them?

    – SiZE
    Nov 29 '18 at 15:19
















  • 3





    the error logs would have more precise details about the error , Internal Server Error can be anything.

    – Muhammad Omer Aslam
    Nov 27 '18 at 7:44






  • 2





    Seems that u have display_errors=off and execution timeout. Check web server error log and under runtime/logs.

    – SiZE
    Nov 28 '18 at 5:28











  • @SiZE debug mode is true in yii2, and max time execution is 0 - that means no limit to execution time.

    – Veshraj Joshi
    Nov 28 '18 at 6:11













  • @VeshrajJoshi 500 means something goes wrong with ur server and error_reporting, display_errors or display_startup_errors are off. Param debug set to true can not guaranty that. Then what about server error logs? Why u cant just read them?

    – SiZE
    Nov 29 '18 at 15:19










3




3





the error logs would have more precise details about the error , Internal Server Error can be anything.

– Muhammad Omer Aslam
Nov 27 '18 at 7:44





the error logs would have more precise details about the error , Internal Server Error can be anything.

– Muhammad Omer Aslam
Nov 27 '18 at 7:44




2




2





Seems that u have display_errors=off and execution timeout. Check web server error log and under runtime/logs.

– SiZE
Nov 28 '18 at 5:28





Seems that u have display_errors=off and execution timeout. Check web server error log and under runtime/logs.

– SiZE
Nov 28 '18 at 5:28













@SiZE debug mode is true in yii2, and max time execution is 0 - that means no limit to execution time.

– Veshraj Joshi
Nov 28 '18 at 6:11







@SiZE debug mode is true in yii2, and max time execution is 0 - that means no limit to execution time.

– Veshraj Joshi
Nov 28 '18 at 6:11















@VeshrajJoshi 500 means something goes wrong with ur server and error_reporting, display_errors or display_startup_errors are off. Param debug set to true can not guaranty that. Then what about server error logs? Why u cant just read them?

– SiZE
Nov 29 '18 at 15:19







@VeshrajJoshi 500 means something goes wrong with ur server and error_reporting, display_errors or display_startup_errors are off. Param debug set to true can not guaranty that. Then what about server error logs? Why u cant just read them?

– SiZE
Nov 29 '18 at 15:19














1 Answer
1






active

oldest

votes


















0














The execution is running longer than the configurations are allowing. Two ways to fix: Break the source data set into smaller parts and execute separately; or change the PHP / POSTgres execution time limit.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53493988%2fbulk-delete-operation-occurs-internal-server-error-in-yii2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The execution is running longer than the configurations are allowing. Two ways to fix: Break the source data set into smaller parts and execute separately; or change the PHP / POSTgres execution time limit.






    share|improve this answer




























      0














      The execution is running longer than the configurations are allowing. Two ways to fix: Break the source data set into smaller parts and execute separately; or change the PHP / POSTgres execution time limit.






      share|improve this answer


























        0












        0








        0







        The execution is running longer than the configurations are allowing. Two ways to fix: Break the source data set into smaller parts and execute separately; or change the PHP / POSTgres execution time limit.






        share|improve this answer













        The execution is running longer than the configurations are allowing. Two ways to fix: Break the source data set into smaller parts and execute separately; or change the PHP / POSTgres execution time limit.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 19:16









        David J EddyDavid J Eddy

        1,3301429




        1,3301429
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53493988%2fbulk-delete-operation-occurs-internal-server-error-in-yii2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks