Skip to main content
February 4, 2009
Question

Running a background process

  • February 4, 2009
  • 6 replies
  • 3336 views
Hi,

I have a retail website, and I am tweaking the final processing page to make it run faster. Right now, our customers wait up to 10 seconds after they hit the confirm button before they see the 'transaction complete' page.

My idea is to take out some of the less important processing and run them after the 'transaction complete' page is displayed to customers.

I am on a shared CF7 hosting with cfschedule disabled. Is there an alternative way to tell CF to run a script in the background?

Thanks,
Min
    This topic has been closed for replies.

    6 replies

    Inspiring
    February 5, 2009
    minli98 wrote:
    > I found a possible solution. It's more a hack than a real solution, but it's
    > very simple. It uses cfhttp to connect to the second script and then cut the
    > connection after 1 second. The second script should continue to run. However,
    > someone said that it's not always reliable.

    The old trick was this <cfhttp...> tag with a timeout of zero. This was
    the old way to fire off an asynchronous process before the days of
    gateways and <cfthread...>.
    February 5, 2009
    I found a possible solution. It's more a hack than a real solution, but it's very simple. It uses cfhttp to connect to the second script and then cut the connection after 1 second. The second script should continue to run. However, someone said that it's not always reliable.

    # <cfhttp
    # url=" http://#CGI.server_name##CGI.script_name#"
    # method="get"
    # timeout="1"
    # />

    http://www.bennadel.com/blog/1062-Ask-Ben-Running-ColdFusion-Asynchronously-Caveman-Style.htm
    Inspiring
    February 4, 2009
    > I am on a shared CF7 hosting with cfschedule disabled. Is there an
    > alternative way to tell CF to run a script in the background?

    If you can get an async CFML gateway configured, then you can make async CF
    requests.

    Read up on sendGatwayMessage() -
    http://livedocs.adobe.com/coldfusion/8/functions_s_02.html - and the
    various other links from that page.

    --
    Adam
    February 5, 2009
    Thanks, I'll check it out.

    quote:

    Originally posted by: Newsgroup User
    > I am on a shared CF7 hosting with cfschedule disabled. Is there an
    > alternative way to tell CF to run a script in the background?

    If you can get an async CFML gateway configured, then you can make async CF
    requests.

    Read up on sendGatwayMessage() -
    http://livedocs.adobe.com/coldfusion/8/functions_s_02.html - and the
    various other links from that page.

    --
    Adam



    Inspiring
    February 4, 2009
    One of the things I like about jQuery (I know this library the best but imagine others work in a similar fashion) is that when you submit a form via a jQuery function, jQuery uses the action attribute of the form tag to determine where it submits *unless* a submit to url is provided in the options object passed into the ajaxForm function.

    I haven't tried it before but you should be able to set the form action attribute to one url, which would be used if JS is off, and set another action url in options object that gets passed into the ajax form function

    Here's a sample of setting up an HTML form to submit via jQuery (the HTML form would use an alternate action page).
    $(document).ready
    (
    function()
    {
    var options = {

    target: '#formOutput', // target element(s) to be updated with server response
    beforeSubmit: showFormRequest, // pre-submit callback
    success: showFormResponse, // post-submit callback
    resetForm: true,
    // other available options:
    url: 'htp://domain.com/blah/blah/blah.cfm', // override for form's 'action' attribute
    type: 'post', // 'get' or 'post', override for form's 'method' attribute
    dataType: 'json' // 'xml', 'script', or 'json' (expected server response type)
    //clearForm: true // clear all form fields after successful submit
    //resetForm: true // reset the form after successful submit

    // $.ajax options can be used here too, for example:
    //timeout: 3000
    };
    // bind form using 'ajaxForm'
    $('#myform').ajaxForm(options);
    });

    Might not be worth the effort of fit into your requirements but wanted to put it out there for you. I have a jQuery-driven CMS I built for a client that I could pull some code samples out for you if that might help.

    Cheers,
    Craig
    February 4, 2009
    Hi Craig,

    Thanks for the explanation and sample code. I am going to look further into it to see if I can use it.

    Rgds,
    Min
    Inspiring
    February 4, 2009
    Depends on the details. Something I do is to use Cold Fusion to do something and then send some information somewhere. I then have scheduled jobs that react to that information.
    Inspiring
    February 4, 2009
    Hi, Min,

    I do not know of a way offhand to do this in CF7 but you might look into using an Ajax library, such as jQuery, to handle this task for you.

    With jQuery (or one of the many other solid Ajax frameworks), you can submit the form data to an XMLHttpRequest, which runs asynchronously in the background. While the XMLHttpRequest is running, you can use jQuery to display a message to the user (a loading icon, add some text to the DOM/page so that the user knows the site is working on their order, and then provide a confirmation screen (or redirect to the transaction complete page) when it's done.

    If you haven't used an Ajax library (or Ajax in general), it can be a bit intimidating but it is a great way to improve the user experience. If this might be of help, I can certainly provide an example or two for you on how ColdFusion and jQery work together on processes such as these.

    Best,
    Craig
    February 4, 2009
    Hi Craig,

    I thought of using Ajax, but it would require that javascript be turned on. We do have Ajax on some pages of our site, but we try to provide alternatives if javascript is turned off. In this case, I don't know how to do the alternative.

    Thanks,
    Min

    quote:

    Originally posted by: craigkaminsky
    Hi, Min,

    I do not know of a way offhand to do this in CF7 but you might look into using an Ajax library, such as jQuery, to handle this task for you.

    With jQuery (or one of the many other solid Ajax frameworks), you can submit the form data to an XMLHttpRequest, which runs asynchronously in the background. While the XMLHttpRequest is running, you can use jQuery to display a message to the user (a loading icon, add some text to the DOM/page so that the user knows the site is working on their order, and then provide a confirmation screen (or redirect to the transaction complete page) when it's done.

    If you haven't used an Ajax library (or Ajax in general), it can be a bit intimidating but it is a great way to improve the user experience. If this might be of help, I can certainly provide an example or two for you on how ColdFusion and jQery work together on processes such as these.

    Best,
    Craig