1

I previously made the post cfhttp in cfloop limit? use cfthread regarding making multiple CFHTTP requests to which I implemented the solution of making a XMLHttpRequest in a JS function to call my CFHTTP request from another file.

I've amended this so that it runs on an intertval timer but I seem to have an issue in that I'm only allowed by the host to make 3 requests per second but although I may set the interval time to even every 7 seconds I still end up timing out because the CFHTTP requests seem to pend and often make the request at the same time (which means it's taking me through the threshold).

I've read Ben Nadel's posts on using CFTHREAD but am having absolutely no joy implementing them at all.

My basic process at the moment is:-

  • Index.cfm contains a JS function that uses a XMLHttpRequest that calls playerSearch.cfm
  • playerSearch.cfm makes the CFHTTP request.
  • playerSearch.cfm then loops round the response and I display the current item from the loop as well as submitting another CFHTTP request to make a bid on the current item in the loop if it meets any of my IF conditions.
  • Index.cfm then keeps making requests every X amount of seconds.

Is there a way I can set the CFHTTP request itself to make its request every X amount of seconds (maybe using the sleep function in CFTHREAD?) and how would I display anything inside a CFTHREAD as I don't seem to be able to?

Also if I were able to make the CFHTTP request itself make the request every X amount of seconds then would I be better just calling that directly and would it keep looping continuously?

Any feedback would be much appreciated!

EDIT:

Index.cfm

<script>

var searchTimer = null,
    searchInterval = 1000,
    startPosition = 0;

function startSearch() {
    if (searchTimer !== null) return;
    searchTimer = setInterval(function () {
        startPosition = startPosition + 16;
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "playerSearch.cfm?startPosition="+startPosition, true);
        xhr.onload = function (e) {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    document.getElementById("counter").innerHTML = xhr.response;
                } else {
                    // Error handling
                }
            }
        };
        xhr.onerror = function (e) {
            // Error handling
        };
        xhr.send(null);
    }, searchInterval);
}

function stopSearch() {
    clearInterval(searchTimer);
    searchTimer = null
}

</script>

playerSearch.cfm

<cfset Variables.startPosition = URL.startPosition />

<cfhttp url="https://utas.fut.ea.com/ut/game/fifa13/auctionhouse?type=player" method="post" result="getPlayer">
    <cfhttpparam type="header" name="Accept" value="application/json" />
    <cfhttpparam type="header" name="Accept-Language" value="en-GB" />
    <cfhttpparam type="header" name="Connection" value="keep-alive" />
    <cfhttpparam type="header" name="Content-Length" value="1" />
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam type="header" name="COOKIE" value="#Arguments.cookieString#">
    <cfhttpparam type="header" name="Host" value="utas.fut.ea.com" />
    <cfhttpparam type="header" name="Referer" value="http://cdn.easf.www.easports.com/soccer/static/flash/futFifaUltimateTeamPlugin/FifaUltimateTeam.swf" />
    <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" />
    <cfhttpparam type="header" name="X-HTTP-Method-Override" value="GET" />
    <cfhttpparam type="header" name="X-UT-Embed-Error" value="true" />
    <cfhttpparam type="header" name="x-flash-version" value="11,7,700,224" />
    <cfhttpparam type="header" name="X-UT-SID" value="#Arguments.sessionID#" />
</cfhttp>

<cfif getPlayer.StatusCode EQ "200 OK">
    <!--- DESERIALIZE RETURNED JSON SO CAN LOOP ROUND EACH RESULT --->
    <cfset Variables.searchResults = DeserializeJSON(getPlayer.FileContent) />

    <!--- IF SEARCH RESULTS RETURNED --->
        <cfset Variables.numResults = ArrayLen(Variables.searchResults.auctionInfo) />
        <cfset Variables.bidsMade = 0 />

        <table width="900" cellpadding="0" cellspacing="0">
            <tr>
                <th width="100" align="left" class="heading">Player Name</th>
                <th width="70" align="left" class="heading">Rating</th>
                <th width="50" align="left" class="heading">Formation</th>
                <th width="80" align="left" class="heading">Position</th>
                <th width="80" align="left" class="heading">Bid Status</th>
                <th width="100" align="left" class="heading">Starting Price</th>
                <th width="80" align="left" class="heading">BIN Price</th>
                <th width="80" align="left" class="heading">Current Bid</th>
                <th width="80" align="left" class="heading">My Bid</th>
                <th width="120" align="left" class="heading">Ends</th>
            </tr>
            <cfloop from="1" to="#Variables.numResults#" index="i"> 

                <cfscript>

                    // DEFAULT BID AMOUNT
                    Variables.bidAmount = 0;

                    // SET BID AMOUNT
                    // IF ITEM HAS BUY NOW PRICE AND IT IS LESS THAN QUICK SELL VALUE THEN BID THAT AMOUNT
                    if (Variables.searchResults.auctionInfo[i].buyNowPrice NEQ 0 AND Variables.searchResults.auctionInfo[i].buyNowPrice LT Variables.searchResults.auctionInfo[i].itemData.discardValue) {
                        Variables.bidAmount = Variables.searchResults.auctionInfo[i].buyNowPrice;
                    }
                    // ELSE IF QUICK SELL VALUE IS 228,231,235,238,242,245 OR 249 BID 200
                    else if (ListFind("228,231,235,238,242,245,249",Variables.searchResults.auctionInfo[i].itemData.discardValue) AND Variables.searchResults.auctionInfo[i].startingBid LTE 200 AND Variables.searchResults.auctionInfo[i].currentBid LT 200) {
                        Variables.bidAmount = 200;
                    }
                    // ELSE IF QUICK SELL VALUE IS 252,256,259 OR 300 BID 250
                    else if (ListFind("252,256,259,300",Variables.searchResults.auctionInfo[i].itemData.discardValue) AND Variables.searchResults.auctionInfo[i].startingBid LTE 250 AND Variables.searchResults.auctionInfo[i].currentBid LT 250) {
                        Variables.bidAmount = 250;
                    }

                    // GET MY CURRENT COIN TOTAL
                    Variables.getCoinTotal = Application.cfcs.Club.getCreditsTotal(SESSION.phishingKey,SESSION.sessionKey);
                    Variables.curCoinsData = DeserializeJSON(Variables.getCoinTotal.FileContent);
                    Variables.curCoins = Variables.curCoinsData.credits;

                    // IF I CURRENTLY HAVE ENOUGH COINS IN ACCOUNT PLACE BID
                    if (StructKeyExists(Variables,"curCoins") AND Variables.bidAmount NEQ 0 AND Variables.bidAmount LT Variables.curCoins) {

                        <cfset Variables.bidData = '{ "bid": ' & Variables.bidAmount & ' }'>
                        <cfset Variables.bidDataLength = Len(Variables.bidData) />

                        <cfhttp url="https://utas.fut.ea.com/ut/game/fifa13/trade/" & Variables.searchResults.auctionInfo[i].tradeID & "/bid" method="POST" result="makeBid">
                            <cfhttpparam type="header" name="Accept" value="application/json" />
                            <cfhttpparam type="header" name="Connection" value="keep-alive" />
                            <cfhttpparam type="header" name="Content-Type" value="application/json" />
                            <cfhttpparam type="header" name="Content-Length" value="#Variables.bidDataLength#" />
                            <cfhttpparam type="header" name="Host" value="utas.fut.ea.com" />
                            <cfhttpparam type="header" name="Referer" value="http://cdn.easf.www.easports.com/soccer/static/flash/futFifaUltimateTeamPlugin/FifaUltimateTeam.swf" />
                            <cfhttpparam type="header" name="X-HTTP-Method-Override" value="PUT" />
                            <cfhttpparam type="header" name="X-UT-SID" value="#SESSION.sessionKey#" />
                            <cfhttpparam type="header" name="COOKIE" value="#SESSION.phishingKey#">     
                            <cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" />
                            <cfhttpparam type="body" value="#Variables.bidData#" /> 
                        </cfhttp>

                        Variables.bidsMade = Variables.bidsMade + 1;

                    } else {

                        Variables.bidAmount = 0;

                    }
                </cfscript>
                <cfoutput>
                    <tr>
                        <td align="left">#Variables.searchResults.auctionInfo[i].itemData.assetID#</td>
                        <td align="left">
                            #Variables.searchResults.auctionInfo[i].itemData.rating# 
                            <cfif Variables.searchResults.auctionInfo[i].itemData.rareFlag EQ 0>
                                &nbsp;
                            <cfelseif Variables.searchResults.auctionInfo[i].itemData.rareFlag EQ 1>
                                (Rare)
                            <cfelse>
                                (Something else)
                            </cfif>
                        </td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].itemData.formation#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].itemData.preferredPosition#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].bidState#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].startingBid#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].buyNowPrice#</td>
                        <td align="left">#Variables.searchResults.auctionInfo[i].currentBid#</td>
                        <td align="left">#Variables.bidAmount#</td>
                        <td align="left">
                            <cfif Variables.searchResults.auctionInfo[i].tradeState EQ "active">
                                <cfset timeLeft = Variables.searchResults.auctionInfo[i].expires />
                                <cfset auctionEnds = DateAdd("s",timeLeft,Now()) />
                                #DateFormat(Variables.auctionEnds,"dd/mm/yyyy")# #TimeFormat(Variables.auctionEnds,"HH:mm:ss")#
                            <cfelse>
                                Ended
                            </cfif>
                        </td>
                    </tr>
                </cfoutput>
            </cfloop>
        </table>
        <br /><br />Bids Made: <cfoutput>#Variables.bidsMade#</cfoutput>
<cfelse><br />
    The search returned an error.
    <cfdump var="#getPlayer#">
</cfif>
Community
  • 1
  • 1
CPB07
  • 679
  • 3
  • 13
  • 23
  • 2
    Instead of describing the code, post the relevant bits. Something pared down, stand-alone and without anything extraneous would help us analyse your issue. I hate to recommend it given all the security issues Adobe are having at the moment, but it sounds like web sockets might be something worth you looking at. Not entirely clear from your description though. – Adam Cameron Jul 07 '13 at 13:33
  • OP updated with code snippets – CPB07 Jul 07 '13 at 20:46
  • To answer one of your questions - _how would I display anything inside a CFTHREAD_ You can't. `cfthread` runs outside of the request context so there is nowhere to return "display" output. You will need to write what you need to a file (or email the contents). – Miguel-F Jul 08 '13 at 18:34

0 Answers0