Good time! I conceived here one idea but did not fully understand how to solve it, the problem is this - there is a php script on the page that puts the data into the database and after successful recording it should not do a large mailing list, this process can be long and I want to do so this script would be executed in a separate file, so that the first script would do its work with the database and, if successful, send a request to a separate php page here. In approximately the same way as this is done through ajax, can you tell me how can this be implemented? or send an xml request to that script so that it starts working?
- Try running the required php script as a separate process. Example on eng SO . - aleks.andr
- one@ aleks.andr do you mean by exec ?? - dantelol
|
2 answers
Without exec, pcntl_exec etc. (they are often blocked and unsafe). You can pull the desired script with a curl without waiting for an answer, for example:
$curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_PORT, $port); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Host: ' . $_SERVER['HTTP_HOST'])); /*Опции запроса, чтобы не дожидаться ответа*/ curl_setopt($curl_handle, CURLOPT_TIMEOUT, 1); curl_setopt($curl_handle, CURLOPT_NOSIGNAL, 1); curl_setopt($curl_handle, CURLOPT_HEADER, false); curl_setopt($curl_handle, CURLOPT_NOBODY, true); curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, true); /*Если используется HTTPAUTH*/ if( !empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW']) ) { curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl_handle, CURLOPT_USERPWD, $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']); } /*Код можно прикрепить, чтобы при обработке проверить подлинность запроса*/ if( $code ) { curl_setopt($curl_handle, CURLOPT_COOKIE, 'curl_code=' . $code); } /*Выполняем*/ curl_exec($curl_handle); curl_close($curl_handle); On the side of the request handler should be:
ignore_user_abort(); In this way, it is invisible to the user - that he initiated the request, and this does not lead to the "unlocking" of the loading of his page.
|
After successfully writing to the database with the usual get request, refer to the php file on the server that will be sent.
|