SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict MarekS's Avatar
    Join Date
    Jan 2003
    Location
    Estonia / Tallinn
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    making request in background and NOT waiting the response

    Hi,
    On site I have user reg functionality and its fast and there is no prob with it.

    Now as an adittion, I also need to implement secondary user reg with same data... targeting totally different host.

    I have the specs that say what to POST, where to post and how to post.

    Bad news is that, the response is slow-coming and if I execute the curl code it just loads and makes MY site new users to wait for few seconds til they can contiune.

    The good news is, I don't really need to show the response results coming from that secondary server to user. Its generally not the end of a world if the secondary registration fails for few times.

    In theory (in my mind)... I would like to send the POST request in another instance or so... not sure if its possible tho due the nature of PHP.

    Question is... how can I solve the POST in background issue technically? What are my chances to keep it simple. Wouldn't want queues/cronjobs

    Thanks,

  2. #2
    SitePoint Addict Wildhoney's Avatar
    Join Date
    Apr 2006
    Location
    Nottingham
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use proc_open for this:

    Code:
    proc_close(proc_open('./script.php', $foo));
    The empty array for the output specs prevents opening any pipes to the new
    process, so proc_open doesn't wait for the execution of script.php to
    finish - the last parameter is just there because it has to be.
    proc_close() closes the process immediately, so your PHP script doesn't
    stop.
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online

  3. #3
    SitePoint Addict MarekS's Avatar
    Join Date
    Jan 2003
    Location
    Estonia / Tallinn
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP manual says
    Note: If you only need a uni-directional (one-way) process pipe, use popen() instead, as it is much easier to use.
    Any comments/thoughts on this one?
    http://www.php.net/manual/en/function.popen.php

  4. #4
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look for "PHP forking" on Google and you will find several examples. One of the more simpler ways is to execute a PHP file using exec or system, and routing the output of the script to a text file or /dev/null, that frees the script that made the command to close whenever it needs to, while the script it set in motion continues.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •