asynchronous curl request after form posted and re

2019-07-19 19:59发布

I have to run curl right after submitting and saving post data into database. When the form data is saved i run curl and redirect to form again.

Is it possible to redirect without waiting for curl to complete? Because in my case curl may take more then a minute.

Regards.

2条回答
forever°为你锁心
2楼-- · 2019-07-19 20:30

You could make use of an exec fork

exec('php /path/to/your/curlscript.php > /dev/null 2>&1 &'); 

The /dev/null 2>&1 & does not log anything and the > after your curlscript.php means it wont wait for anything.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-07-19 20:35

I think the best solution is to call the page without cURL, using just javascript in async mode (for example - but depends on which kind of project are you working to).

For example

jQuery(function($){
    $('#submit-button').on('click', function(e){
        e.preventDefault();
        $.ajax({
            type: 'POST',   
            url: 'your-url.php',   
            data: $('#your-form').serialize(),
            success: success,
            dataType: dataType 
        });

        window.location.replace("your-next-page");
    });
});

Pay attention that in this way you'll not be notified of errors while storing the data...

查看更多
登录 后发表回答