473,383 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

cron or command line: run a very long php script


Hi there,

I have a list of links which point to e.g.
thescript.php?album=somePictures1
thescript.php?album=somePictures2

This list is about 3000 links. Each album may have 500 or more pictures in it.
the script looks in the specified dir, and creates thumbnails if they are not
present. So, displaying a particular album often takes quite a while. I've set
the proper php.ini stuff to accomodate the long script_execution's. Thats all
working fine.

Now, I dont want the end user to have to wait for the thumbs if they land on an
album that has not yet had thumbnails created.

So the question is, what is the best way to run all those links automatically,
thereby creating all the thumbs?

Thanks for your time,
Aug 17 '07 #1
4 4396
I have a list of links which point to e.g.
thescript.php?album=somePictures1
thescript.php?album=somePictures2

This list is about 3000 links. Each album may have 500 or more pictures in it.
the script looks in the specified dir, and creates thumbnails if they are not
present. So, displaying a particular album often takes quite a while. I've set
the proper php.ini stuff to accomodate the long script_execution's. Thats all
working fine.

Now, I dont want the end user to have to wait for the thumbs if they land on an
album that has not yet had thumbnails created.

So the question is, what is the best way to run all those links automatically,
thereby creating all the thumbs?

Thanks for your time,
As you suggested in your subject line, probably the best route to go
would be to set up a command line script to process the file, and use
cron to do it regularly if new files are being added all the time (or
just process files at the time of introduction in the system).

Just remember, in command-line scripts for PHP, you have to first give
a path to the interpreter like so:
#!/usr/bin/php

Just replace "/usr/bin/php" with the path to your interpreter.

You will also of course, have to go through all directories not just
one, so this is a brief recursive function to iterate a directory
structure. It takes the root directory containing images and their
directories as its parameter. Just replace the comment with the
appropriate means of processing your images and making thumbnails:
//(not tested)
function iterateDir($dir){

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file != "." && $file != ".."){
if(is_dir($file)){
iterateDir($file);
}else{
//...process file...
}
}
}
closedir($dh);
}
}
}

Aug 17 '07 #2
C.
On 17 Aug, 19:13, "burgermeiste...@gmail.com"
<burgermeiste...@gmail.comwrote:
>
This list is about 3000 links. Each album may have 500 or more pictures in it.
the script looks in the specified dir, and creates thumbnails if they are not
present.

As you suggested in your subject line, probably the best route to go
would be to set up a command line script to process the file,
No - that's the worst route to go.
process files at the time of introduction in the system
is the best solution.

Admittedly, that is not going to solve the problem for existing
images. But tying a check/generation into the viewing page provides a
simple interface to updating the images which should only need done
once.
Just remember, in command-line scripts for PHP, you have to first give
a path to the interpreter like so:
#!/usr/bin/php
....if you are running on a POSIX type system, but you'll also need to
make the script executable. RTFM - http://www.php.net/manual/en/features.commandline.php

Yes you do it via a cron job if you prefer - there's lot of
discussions about how to do this - and even toolkits which emulate it
when you don't have access to cron. But for your purposes this is just
adding unnecessary complexity.

C.

Aug 19 '07 #3
On Sun, 19 Aug 2007 12:38:15 -0000, "C." <co************@gmail.comwrote:
>...if you are running on a POSIX type system, but you'll also need to
make the script executable. RTFM - http://www.php.net/manual/en/features.commandline.php

Yes you do it via a cron job if you prefer -
Ok, thanks, I guess my question was more about whether my thumbnail generation
script will choke if the cron, command line script, etc tries to run too many
instances of it at once. I dont know how that part would work. Like if I run
script.php?album=dir1 and dont have a way for the cron to know whether the
script is done with dir1 before moving on to dir2.

Jeez, just this one parent dir with its 3300 sub dirs is going to take around
100 hours.
Aug 19 '07 #4
On Aug 19, 5:47 pm, J. Frank Parnell <p...@edgecity.ufowrote:
On Sun, 19 Aug 2007 12:38:15 -0000, "C." <colin.mckin...@gmail.comwrote:
...if you are running on a POSIX type system, but you'll also need to
make the script executable. RTFM -http://www.php.net/manual/en/features.commandline.php
Yes you do it via a cron job if you prefer -

Ok, thanks, I guess my question was more about whether my thumbnail generation
script will choke if the cron, command line script, etc tries to run too many
instances of it at once. I dont know how that part would work. Like if I run
script.php?album=dir1 and dont have a way for the cron to know whether the
script is done with dir1 before moving on to dir2.

Jeez, just this one parent dir with its 3300 sub dirs is going to take around
100 hours.
Just to clarify on what C added to this thread: he/she is right. You
will need some script to run once and to process all the existing
images from command-line, and will probably want to just run the
routine on new, incoming images after that. If that's not a
possibility for some reason, *then* cron is the way to go.

Anyways, about cron or CLI choking: that's the reason I posted that
recursive function. You won't need multiple instances to run on each
directory, you can instead run one script that will process all
directories. Of course, like you said, this is going to take a long
time to do because you have so many images. That means you should do
these two things:
1) Be sure that you don't have any time limits set on the script's
execution time, i.e. use the function: set_time_limit(0)
2) Fully test the script before you run it on all your images. You
don't want to run the script, wait 100 hours or whatever, and then
find out that the script causes a weird distortion on some of your
files.

I hope this helps you.

Aug 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
4
by: vagrantbrad | last post by:
I'm using python 2.4 running on Fedora Core 4. I have written a python program called ipscan.py that checks the external ip address of my cable internet connection, and on change, will update the...
3
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the...
0
by: Nikola Skoric | last post by:
Hello, I have a few lines of code retrieving a web page and saving some variables from it to a log. And everything works nice from command line. but, when I make a cron job, I get an error: ...
3
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify...
4
by: Phil | last post by:
I have a php script that queries some Oracle DB and outputs a single line of plain text with <brat the end for each query. This is Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS...
3
by: Zudnic | last post by:
Hi, long time listener, first time caller so to speak. Thanks to everyone who has answered other questions that I've found and used. I'm self-taught in Perl and have been hacking at it for more...
4
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying...
0
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.