Solved

How do I wait for a cfexecute tag to finish before continuing?

Posted on 2006-11-02
15
824 Views
Last Modified: 2013-12-24
I have a site that allows people to add files to their basket and when they are done I zip it up and let them download the zip file. I have found out that when the zip file is 400mb or so and they are trying to download it the zip file is often corrupted. It turns out that the cfexecute tag is allowing the following code to execute before it's completed. Is there a way to wait for the process to finish before I continue on to the next code?

I've tried putting it into a java program but I kept getting null pointer exceptions and I'm very aggravated with it. I need a solution asap, please help!


0
Comment
Question by:jbrahy
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862408
Can you rename it once it is done creating the zip. This way the file will only be there when it is ready to be downloaded. You can easily check for the file using FILEEXISTS.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862555
that would be great if I knew when it was done creating the zip. but that's the problem that I'm having is that I don't know when it's done. do you have any ideas of how to know when it's done? is there a way to list windows processes so I can grep for the particular one that I launched. I guess I would also need the process id for it from cfexecute.
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862723
You can redirect the user to a "waiting" page and will know when it is done when the file is there.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862767
the problem is that the file is there while it is adding files. it's just increasing in size.
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862772
Exactly! That is why I suggested renaming it as soon as it is done. The temporary loading file is not what you will be checking for. You will check for the final filename which will only be there in complete form.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862809
I understand what you mean by renaming the file, but when I pass the filename and the name of the zip file to 7zip to create the zip file, it doesn't give me the opportunity to rename it after it is done creating the zip file. I would have to run another process to rename the file but that would have to be done after the program is finished creating the zip file. And that's my problem, I don't know when the zip file is done being created.

I could try to rename it in a loop but it won't let me move it until it is done. Is there a way to ignore errors and keep looping?

0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17863138
CFTRY/CFCATCH will catch errors.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:jbrahy
ID: 17863206
ok, I'll try it and let you know how it goes, thanks
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 17865799
why not do this:
when they are finished adding files and they click "Done"
1) call your zip cfc which starts zipping
2) at the end of the zip code use cfheader & cfcontent like:
<cfheader name="content-disposition" value="inline; filename=#whatevername#.zip">                              
<cfcontent type="application/unknown" file="#ZipPath##whatevername#.zip" deletefile="no">
where zipPath is absolute path "D:\websites\zipfiles\"
When the zip is finished zipping - cfcontent will push the file out to the user in the form of a file download dialog
It won't try to do this until the zip is finished zipping.

I just read your original post - I guess I assumed you were using one of the zip cfc's available.
Or is that the java program you're having trouble with that you mentioned.
That's really how you should be doing it - once you get it to work of course.            
0
 
LVL 1

Expert Comment

by:DAJED
ID: 17865871
That is good,

ASSUMING THAT YOU ARE USING CFMX7

Alternatively, you can create a thread and wait for a specified period of time.  After the wait, then you will check for the datelastmodified.  If it is greater than a specified time (you decide) then you can say that the file is finished.

Consider this.
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset DM = 0>
<cfset TimeLimit = 30> <!--- File has to NOT be modified for that length of time --->
<cfset SDte = Now()>
<cfset CDte = Now()>
<cfloop condition="#DM# LT #TimeLimit#">
    <cfset thread.sleep(4000)> <!--- wait for 4 seconds --->
     <!---
             1.  Read the file
             2.  Get the file's date last modified  
             3.  Check the value of Sdte
                   a) if SDte is zero then give SDte the value of the file's date last modified
                   b) if SDte is NOT zero give CDte the value of the file's date last modified
             4. Give DM the value of the time difference (in seconds) of SDte and CDte
     --->
</cfloop>
you can assume that the file IS finished because:

You are only going to START the creation the script once the client is finished adding his/her files.

Hope I helped
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870792
This is what I've been trying but it's moving the partial file and not erroring out when the file is still being written to. I'm going to try to get the date modified like DAJED suggested and hopefully that will work.

thanks

 
<CFEXECUTE
      OUTPUTFILE="d:\sites\www.thissite.com\www\downloads\output.txt"
      TIMEOUT="90"
      NAME="C:\Program Files\7-Zip\7z.exe"
      ARGUMENTS="a -tzip #tempZipPath# #filenames# ">
</CFEXECUTE>

<CFLOOP from="1" to="59" index="index">
      <CFSET thread = CreateObject("java","java.lang.Thread")>
      <CFSET thread.sleep(1000)>
      <CFTRY>
            <CFFILE ACTION="MOVE" source="#tempZipPath#" destination="#zipPath#">
            <CFIF FileExists(zipPath)>
                  file exists
                  <CFFLUSH>                  
                  <CFCONTENT type="application/x-zip">
                  <CFLOCATION url="#zipURL#">
            <CFELSE>
                  doesn't exist
                  <CFOUTPUT>#zipPath#</CFOUTPUT>.
                  <CFFLUSH>                  
            </CFIF>            
            <CFCATCH>
                  <CFOUTPUT>#index#</CFOUTPUT>.
                  <CFFLUSH>                  
                  </CFCATCH>
      </CFTRY>
</CFLOOP>


0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 17870855
ok look - you're looking at it wrong.
get rid of the cfexecute
get rid of the loop and the cflocation and the cffile move (you don't need to move anything I don't believe - just zip files from where they to a zip at any location you choose - the zip cfc should show you how to supply the path)
actually, scratch everything above and use one of the zip cfc's like the one I posted in other thread.
It should give you instructions on how to throw your list of files at it and it will zip them.
Do just that first to make sure all is swell

Then use the cfheader and cfcontent as I posted above.

It works perfect.
This isn't just something I threw together to answer your question.

Now that I see your code - the problem is how you're doing it.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870884
ok, I'll try that and let you know
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870945
Thank you all for your time!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 17870956
you're welcome and good luck
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now