1

I just wanna ask something about Yii. I realize that Yii page (controller - method) cannot be access in same time (with same browser, different tab). The page must be completed process first before user can open another page.

class SiteController extends CController {

    public function actionIndex() {
        echo "Test1";
        sleep(10);
        echo "Test2"
    }

    public function actionIndex2() {
        echo "Test1";
        sleep(10);
        echo "Test2";
    }

}

For example, when I access http://test.com/site/index at 13.00, and http://test.com/site/index2 at 13.01, http://test.com/site/index will be rendered at 13.10 and http://test.com/site/index2 will be rendered around 13.20 or 13.21. What I am expecting is the code will run parallel, the first one will be finish in 13.10 and the second one will be finish in 13.10 or 13.11. Like php script below (rename it test.php), and run in separate tab (but same browser).

<?php
echo "Test1";
sleep(10);
echo "Test2";
?>

So Yii can response multiple request in same time without completing previous request. Same problem I found in here: http://www.yiiframework.com/forum/index.php/topic/41358-multiple-simultaneous-http-requestssolved/ and here http://www.yiiframework.com/forum/index.php/topic/11881-write-delay-with-sessionscache/

I am still finding the best solution. I'm trying this Yii framework async request and PHP Asynchronous Method Call In The Yii Framework for now...

Thanks

Community
  • 1
  • 1
Jef
  • 869
  • 4
  • 13
  • 27
  • 1
    If you're using file-based sessions, request 1 will lock the session file and request 2 will not be able to open it until request 1 finishes. – DCoder Jul 23 '13 at 15:23
  • DCoder is right. So this is not a Yii issue but a general problem with any PHP script that uses file based sessions. As a workaround you could use the `CDbHttpSession` component. – Michael Härtl Jul 23 '13 at 21:31
  • Hi DCoder & Michael, if you make a method that only contain download file by "readfile" in PHP, you cannot execute (or download, exactly) different file in Yii (actionDownload for example), cause the method waiting until user download finished. I think Yii mechanism will lock the session file at the initial. So, I decide to use "session_write_close()" when I want user to execute the method parallel. – Jef Mar 05 '14 at 03:07

0 Answers0