headhunter
Posts: 130
|
| Posted: 06/08/2009, 1:13 PM |
|
Hi,
Is this possible in CCS:
I have a image gallery batch importer/converter php function/class and this is what it does:
-list the content of a uploaded folder with images
-resizes the images to thumbnails and webview sizes (4 sizes)
-put a watermark on the images (optional)
-insert the images (records) into the database.
Now, my problem is that when you have a lot of images to process it takes some time to complete. I want to output to a status window how far the process is at every image it is processing. For example echo each filename with its number, one per line (this can be done in the forloop inside the function).
is this possible?
Thanks in advance.
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/09/2009, 6:36 AM |
|
Hi
In thinking about this. It sounds like an interesting thing to try and build.
My first pass at this might sound convoluted but I think I would try the following. If there is another way I would be interested in hearing that. If you would like me to build it for you... Let me know.
1:)
I would build an ajax service that would take a file name as a parameter. This service would check if the file existed then only execute the unix shell command ' tail ' on that file name and return the result to the calling page. If the filename did not exist the service would return a 'DONE' flag of some kind.
2:)
Create a new script that only uses the batch class to do the batch conversion only.
Modify the Batch Conversion class to take the same filename as above and when called to run a batch, it would open that filename for write. As it processed each file, write the image filename being processed to that file as it ran, adding a newline after each filename. After completely cnverting all files, delete the filename. After testing this script, set it up to run as a background server task. IE: remove all screen / HTML output. Easiest place to do this would be the before output event if you created this in CCS.
The two scripts above would be the scripts that would support your main client HTML page to be able to report status of the conversion.
3:) Your main web page...
Create this page with a couple of extra tunctions.
On the PHP side of this page:
Create a unique file name (maybe using timestamp) that can be used as calling parameters to the above two scripts. Add code that will call the batch conversion script with parameters including the new unique file name in the background. If you need an example for that, let me know.
On the HTML side of this page:
Create a timer function in javascript that will call the ajax service with the same unique filename and display the image filename returned from that function on the page.
I thnk this method should work for you and do what you want.
Some considerations need to be made and added. Such as when the background conversion should be executed. Some testing needs to be sure that the file created containing the list of converted files can be read before that file is closed. IE: can current data come from it while it is being written by the converion script. If not, modifications would need to be done to ensure flush of the write buffers. Not to difficult.
Also with some imagination the ajax script could also reutrn percent complete etc with some minor changes. You could even add a progress bar by doing it this way.
Anyway, Let me know how that sounds to you and let me know if you have any questions.
John
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
headhunter
Posts: 130
|
| Posted: 06/09/2009, 10:45 AM |
|
hi John,
thanks for your prompt reply!
your idea sounds pretty good to me but will only work on Linux/unix, just because of the tail program that is not available in windows.
I make my CMS as compatible as I can to work on both Linux and windows machines (But I prefer Linux).
maybe some other approach: after every image that is prosessed, a record for the image is added in the database. so maybe instead of writing to a text file and read it again to pass the content it is maybe easier to read from the database?
If I got some time I will certainly try your method.
(my wife is pregnant and next week my 4th child will be born. Development is pure hobby so I can't work on it at work)
And offcourse, you may try as well :)
kind regards.
Bart
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/09/2009, 11:09 AM |
|
Hi
You could do that but you have to consider the possibility of several instances of this script potentially running. So what would you do create a unique table and delete it?? Maybe,
Easier to simulate tail in Windows. Does not look that hard. I did a google search on windows equivalent of tail and found many solutions.
BTW Congrats on the new baby. Hope Mom and Baby do well.
John
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
headhunter
Posts: 130
|
| Posted: 06/09/2009, 11:39 AM |
|
John,
I'll try your method.
I keep you informed.
Regards,
Bart
|
 |
 |
RonB
Posts: 228
|
| Posted: 06/10/2009, 1:06 AM |
|
Hi there...
I was thinking... You could set a session variable at the start of the script CCSetSession("image_script",1) and at the end of the script CCSetSession("image_script",0)
create a service page that checks the session variable and returns it's value.
Use the suggested JavaScript timer function to call the page and redirect to a done page if the returned result equals 0
you could use a nice animated gif to look at during the scripts progress 
just a suggestion.
Ron
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/10/2009, 6:12 AM |
|
Hi Ron
Not a bad Idea except, the background script will not have a session variable. It is not running in a browser but on the server.
He also wanted to see the filename being processed I think.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
RonB
Posts: 228
|
| Posted: 06/14/2009, 3:33 AM |
|
Hey there!!
I was suggesting he would edit the image processing script doing the work on the server. He could set the session variable at the start, use another session variable to set the current processed image and change that with each file getting processed. That way he has both options.
The other page could use ajax to make a call to another on the server page that gets these two values and retuns them for use in the client sie javacscript. That's what ajax can be used for isn't it?
Ron
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/14/2009, 8:29 AM |
|
Hi Ron
Yup I think That is how to do it. (session variables will not be available) So you will notice step one above is to create an ajax service page to return tha filename being processed.
I am pretty sure the client routine that starts the conversion process will not have access to any session variables.
Have not tested that
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
headhunter
Posts: 130
|
| Posted: 06/14/2009, 9:07 AM |
|
Hi guys,
thanks for the responses.
For the moment as it is programmed I can pass session variables because the script is triggered by the button on-click event of a insert form. The script that is doing the transformations (image prosessing) is php and is running (off course) on the server. It is no problem passing session variables to the script.
This will not work when the script is called servers side with CLI (command line interface) of php.
I did not look further into it at the moment because I have not had the time yet.
kind regards,
Bart
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/14/2009, 7:31 PM |
|
Hi
Sounds interesting.
You are already running the convesion script in the background and the background script is getting session variables?
If so that is cool I did not think that was possible. So, Live and learn.
Or is your onclick button just linking to another page and you are waiting on that page for the conversion to complete??
Why are you using PHP CLI??
Maybe I have missed something.
I am curious.
Thanks
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/14/2009, 7:41 PM |
|
BTW
If you would, can you tell me how you are starting your background script so it can get session variables from the calling page??
Are you using a header parameter??
I always belived that session variables were related to a browser instance. So I did not think it possible for a script running without a browser could get session variables.
That would be very helpful to me and I will have learned something.
Thanks in advance
John
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
headhunter
Posts: 130
|
| Posted: 06/14/2009, 11:37 PM |
|
John,
I mean with a script running on the server that it is server side running, not that it is running in the background. maybe my words are somewhat confusing... sorry.
I still have to wait on the page where the form is submitted until the script has completed.
But as I mentioned before, this method works for me now and is doing it's job like it should.
If I have more time I can spend some time to fine-tune this with some ajax magic, but it will be for a later time. I thought there was maybe a simple way and easy to implement, but that thought was wrong 
In the meantime I will follow this topic (for other suggestions) and when I have some progress I post it back.
Thanks.
Bart
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 06/15/2009, 6:46 AM |
|
Ok Bart
If you need help with it, Let me know.
Sounds like something fun to do.
John
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |