Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Run PHP to generate a file on the server side



3:31 am on Dec 19, 2011 (gmt 0)

5+ Year Member

Hi All,

I operate a Wordpress web site, and my experience with PHP is limited to modifying Wordpress templates to achieve the HTML output I'm looking for.

I have a situation where my wordpress template is calling Yahoo Pipes to get a PHP array based on RSS aggregation to display on a page. Problem is, it takes about 7 seconds to load the page.

If I do this synchronously with the page load (which is all I've ever done), it seriously delays the page load.

What I would like to do is separate out the PHP call to Yahoo Pipes into another process - basically run it every 15 minutes or so, and generate an output file on my server. Then, I could include that output file in my PHP load of the home page for my site.

Does that make sense? Seems to me I should be able to do this using cron or something like that, but I've never run any PHP except via my wordpress install.



5:01 pm on Dec 19, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Yes, a cron is what you want, but I wouldn't run it every 15 minutes if it's taking 7 seconds to load. This (usually) means it's using a fairly intense amount of system resources, and knowing the way many PHP scripts are written, probably storing a lot of data in memory. If you're in a shared environment, your host might yell at you. :-)

Anyway you just create the script to do what you want - these days the easiest way to create the cron is go into your hosting management control panel to create the cron job itself. You would set the time values, then use the full system path to the script - not the url/uri:

php /home/var/www/example.com/mycron.php

You might have to specify the full path to php,

/usr/bin/php /home/var/www/example.com/mycron.php

Your system paths will be different, but that's the gist. Your CP will have help files on how to set the time values. Make sure cron logging is enabled, this will give you good info if the script errors or you have a bad path.

Experiment with a small script that does something like write to a file or email you to test it before jumping in to the live script.

Featured Threads

Hot Threads This Week

Hot Threads This Month