Поток. Набор CurrentPrincipal в Application_AuthenticationRequest не установлен позже в приложении

Многопоточность означает выполнение нескольких задач или процессов одновременно, мы можем достичь этого в php, используя следующий код, хотя прямого способа достижения многопоточности в php нет, но мы можем достичь почти таких же результатов следующим образом.

chdir(dirname(__FILE__));  //if you want to run this file as cron job
 for ($i = 0; $i < 2; $i += 1){
 exec("php test_1.php $i > test.txt &");
 //this will execute test_1.php and will leave this process executing in the background and will go         

 //to next iteration of the loop immediately without waiting the completion of the script in the   

 //test_1.php , $i  is passed as argument .

}

Test_1.php

$conn=mysql_connect($host,$user,$pass);
$db=mysql_select_db($db);
$i = $argv[1];  //this is the argument passed from index.php file
for($j = 0;$j<5000; $j ++)
{
mysql_query("insert  into  test   set

                id='$i',

                comment='test',

                datetime=NOW() ");

}

Это выполнит test_1.php два раза одновременно, и оба процесса будут выполняться в фоновом режиме одновременно, так что таким образом вы можете добиться многопоточности в php.

Этот парень проделал действительно хорошую работу. Многопоточность в php.

.

6
задан Ralph Shillington 1 May 2009 в 00:46
поделиться

2 ответа

You surely have resolved your problem by now but just in case, if you are using the RoleProvider from ASP.NET, the RoleManagerModule overwrites the GenericPrincipal object created by the FormsAuthenticationModule and replaces it with a RolePrincipal object during the PostAuthenticateRequest: http://www.asp.net/Learn/Security/tutorial-11-vb.aspx

6
ответ дан 10 December 2019 в 02:53
поделиться

Убедитесь, что вы реализовали класс для интерфейса IIDentity и Iprincipal, а затем используете что-то вроде следующего кода для назначения currentprincipal.

    Dim userIdentity As CustomIdentity
    userIdentity = New CustomIdentity(username, True,"forms", sessionId)

    Dim principal As New CustomPrincipal(userIdentity, arrRoles)
    HttpContext.Current.User = principal
    System.Threading.Thread.CurrentPrincipal = principal
0
ответ дан 10 December 2019 в 02:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: