By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,068 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,068 IT Pros & Developers. It's quick & easy.

running php script?

P: n/a
ok... im not quite sure how to describe my problem.
i have a php script that runs through my entire php site and writes the
resulting output to html files. this is necessary as the nature of the
hosting available to me for this particular page prohibits me from using
php/mysql as i would like.

my script works simply by using output buffers and an include
the relevant section of code is as follows:

ob_start();
include($source.$pagename);
$page_buffer = ob_get_contents();
ob_end_clean();

i was wondering if there is a way i can do this without using the include,
because the script only works when it is in the same directory as the site.
this arrangement does not suit me, as i would rather be able to store the
script in a separate folder.

Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi,
ob_start();
include($source.$pagename);
$page_buffer = ob_get_contents();
ob_end_clean();

i was wondering if there is a way i can do this without using the include,
because the script only works when it is in the same directory as the site.
this arrangement does not suit me, as i would rather be able to store the
script in a separate folder.


If the included file is on the same Server, you can give the
relative (or absolute) path to the file to include. It
doesn't need to be in the same directory.

Greetz
Paul.
Jul 17 '05 #2

P: n/a

"Sticks" <sa**********@yahoo.com> wrote in message
news:3f********@usenet.per.paradox.net.au...
ok... im not quite sure how to describe my problem.
i have a php script that runs through my entire php site and writes the
resulting output to html files. this is necessary as the nature of the
hosting available to me for this particular page prohibits me from using
php/mysql as i would like.

my script works simply by using output buffers and an include
the relevant section of code is as follows:

ob_start();
include($source.$pagename);
$page_buffer = ob_get_contents();
ob_end_clean();

i was wondering if there is a way i can do this without using the include,
because the script only works when it is in the same directory as the site. this arrangement does not suit me, as i would rather be able to store the
script in a separate folder.


My first thought is to create an array with your directory names that you
want to scan

$allDirs =
array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac
he/site1/htdocs") etc...

then iterate through the array and subsequent directory files.

while (list(,$dirName) = each($allDirs) {
// create an array of all files
$allFiles = scandir($dirName);
while (list ($key,$fileName) = each($allFiles) {
// each file within each directory
$page_buffer to $fileName stuf......
}
}

Jul 17 '05 #3

P: n/a
perhaps i havent been clear enough
i dont want to use includes to perform this task. i would like to get the
html output of a php script that is quite complicated and uses a variety of
includes of its own which i do not wish to rewrite unless i absolutely have
to. these includes are disturbed when my script resides in a different
directory to the page.

as it stands, the script works. it just isnt an ideal solution.
i am looking for something along the lines of the exec() command, only for
executing php scripts.

<xyzzy> wrote in message news:Xf********************@comcast.com...

"Sticks" <sa**********@yahoo.com> wrote in message
news:3f********@usenet.per.paradox.net.au...
ok... im not quite sure how to describe my problem.
i have a php script that runs through my entire php site and writes the
resulting output to html files. this is necessary as the nature of the
hosting available to me for this particular page prohibits me from using
php/mysql as i would like.

my script works simply by using output buffers and an include
the relevant section of code is as follows:

ob_start();
include($source.$pagename);
$page_buffer = ob_get_contents();
ob_end_clean();

i was wondering if there is a way i can do this without using the include, because the script only works when it is in the same directory as the site.
this arrangement does not suit me, as i would rather be able to store the script in a separate folder.


My first thought is to create an array with your directory names that you
want to scan

$allDirs =

array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac he/site1/htdocs") etc...

then iterate through the array and subsequent directory files.

while (list(,$dirName) = each($allDirs) {
// create an array of all files
$allFiles = scandir($dirName);
while (list ($key,$fileName) = each($allFiles) {
// each file within each directory
$page_buffer to $fileName stuf......
}
}

Jul 17 '05 #4

P: n/a
Sticks wrote:
[re-ordered you post because top-posting is evil :o)]
<xyzzy> wrote in message news:Xf********************@comcast.com...

"Sticks" <sa**********@yahoo.com> wrote in message
news:3f********@usenet.per.paradox.net.au...
ok... im not quite sure how to describe my problem.
i have a php script that runs through my entire php site and writes the
resulting output to html files. this is necessary as the nature of the
hosting available to me for this particular page prohibits me from using
php/mysql as i would like.

my script works simply by using output buffers and an include
the relevant section of code is as follows:

ob_start();
include($source.$pagename);
$page_buffer = ob_get_contents();
ob_end_clean();

i was wondering if there is a way i can do this without using the include, because the script only works when it is in the same directory as the

site.
this arrangement does not suit me, as i would rather be able to store the script in a separate folder.


My first thought is to create an array with your directory names that you
want to scan

$allDirs =

array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac
he/site1/htdocs") etc...

then iterate through the array and subsequent directory files.

while (list(,$dirName) = each($allDirs) {
// create an array of all files
$allFiles = scandir($dirName);
while (list ($key,$fileName) = each($allFiles) {
// each file within each directory
$page_buffer to $fileName stuf......
}
}

perhaps i havent been clear enough
i dont want to use includes to perform this task. i would like to get the
html output of a php script that is quite complicated and uses a variety of
includes of its own which i do not wish to rewrite unless i absolutely have
to. these includes are disturbed when my script resides in a different
directory to the page.

as it stands, the script works. it just isnt an ideal solution.
i am looking for something along the lines of the exec() command, only for
executing php scripts.


I'm not sure I understand your problem, but if you want to execute php scripts
on Linux, you can use

/pathinfo/php -q /pathinfo/scriptname.php

from the command line or a cron job. The "-q" suppresses HTTP headers. Or you
could do:

/pathinfo/php -q /pathinfo/scriptname.php > index.html

to send all output from that php script to a file called index.html. Be careful
with this, though, as it's easy to overwrite the wrong files...

HTH,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #5

P: n/a
this is *almost* what im looking for
trouble is, im running a windoze XP box.... is there any way to do the
'greater than' output to file thing in windoze?
and the other trouble is that if i want to perform that action from a php
script i have to use 'exec', which is not ideal if i want to move the script
to a *nix server some time in the future (which is highly likely)

the biggest issue is that running the script from any directory other than
the directory in which the page to export resides plays merry havoc with the
document relative paths in the script.
perhaps i should clarify - i have an entire website designed in php, built
off a mysql database, complete with a stack of includes and images and
what-have-you. the problem is that the hosting available to the organisation
that the website is for decided to pull the pin on their previous hosting
plan and are not willing to shell the extra $ for php/mysql hosting. my idea
then was to create this script which parses every single php page it can
become aware of (i had to adjust the databases and scrips a little bit to
respond to a $htmldump flag) and then creates new page names based on
obvious content. it then creates a table of all of the pages it created and
what those pages were created from... say for eg:
"page.php?frame=listbuild.php&hw_type=printers " becomes "printerslist.htm".
the script then looks through ALL of the newly created html pages for links
that belong to the old php site and updates them to the corresponding html
link, as well as copying other files and folders to recreate the site
structure.

the way the script is designed (and i might add that although it is
functional it is one piss poor piece of programming and i am embarrassed to
show it to people) is such that it MUST reside in the same directory as the
website it is dumping. i can see no other way to do it with output buffers
and includes (as i have been doing) without rewriting the entire website to
take into account the relocation of the output script. i REALLY do not want
to do this.

thank you very much for the reply though. i will definitely investigate
whether this will work as a band-aid solution.
sticks

"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:3F***************@glassgiant.com...
Sticks wrote:
[re-ordered you post because top-posting is evil :o)]
<xyzzy> wrote in message news:Xf********************@comcast.com...

"Sticks" <sa**********@yahoo.com> wrote in message
news:3f********@usenet.per.paradox.net.au...
> ok... im not quite sure how to describe my problem.
> i have a php script that runs through my entire php site and writes the > resulting output to html files. this is necessary as the nature of the > hosting available to me for this particular page prohibits me from using > php/mysql as i would like.
>
> my script works simply by using output buffers and an include
> the relevant section of code is as follows:
>
> ob_start();
> include($source.$pagename);
> $page_buffer = ob_get_contents();
> ob_end_clean();
>
> i was wondering if there is a way i can do this without using the include,
> because the script only works when it is in the same directory as the site.
> this arrangement does not suit me, as i would rather be able to store
the
> script in a separate folder.
>
>
>
>
>
My first thought is to create an array with your directory names that
you want to scan

$allDirs =

array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac
he/site1/htdocs") etc...

then iterate through the array and subsequent directory files.

while (list(,$dirName) = each($allDirs) {
// create an array of all files
$allFiles = scandir($dirName);
while (list ($key,$fileName) = each($allFiles) {
// each file within each directory
$page_buffer to $fileName stuf......
}
}

perhaps i havent been clear enough
i dont want to use includes to perform this task. i would like to get

the html output of a php script that is quite complicated and uses a variety of includes of its own which i do not wish to rewrite unless i absolutely have to. these includes are disturbed when my script resides in a different
directory to the page.

as it stands, the script works. it just isnt an ideal solution.
i am looking for something along the lines of the exec() command, only for executing php scripts.


I'm not sure I understand your problem, but if you want to execute php

scripts on Linux, you can use

/pathinfo/php -q /pathinfo/scriptname.php

from the command line or a cron job. The "-q" suppresses HTTP headers. Or you could do:

/pathinfo/php -q /pathinfo/scriptname.php > index.html

to send all output from that php script to a file called index.html. Be careful with this, though, as it's easy to overwrite the wrong files...

HTH,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

Jul 17 '05 #6

P: n/a

"Sticks Random" <ba***********@hotmail.com> wrote in message
news:3f**********************@freenews.iinet.net.a u...
this is *almost* what im looking for
trouble is, im running a windoze XP box.... is there any way to do the
'greater than' output to file thing in windoze?
and the other trouble is that if i want to perform that action from a php
script i have to use 'exec', which is not ideal if i want to move the script to a *nix server some time in the future (which is highly likely)


This is cut from another post by Nikolai Chuvakhin here in this NG:

"
Spawn your asynchronous process via an exec() call with background
execution (& operator; Unix only). Examples:

exec ('myprogram &');
// executes a standalone program in the background

exec ('wget http://server.com/path/script.php --quiet -O /dev/null &');
// executes a PHP script in the background
// via the standard interface

exec ('php /path/script.php &');
// executes a PHP script in the background
// via command-line interface
"

Won't that work for you on a *nix box?

<snipped>

--
Dag.
Jul 17 '05 #7

P: n/a
Sticks Random wrote:
[Post moved to bottom because top-posting is evil :o) ] "Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:3F***************@glassgiant.com...
Sticks wrote:
[re-ordered you post because top-posting is evil :o)]
<xyzzy> wrote in message news:Xf********************@comcast.com...
>
> "Sticks" <sa**********@yahoo.com> wrote in message
> news:3f********@usenet.per.paradox.net.au...
> > ok... im not quite sure how to describe my problem.
> > i have a php script that runs through my entire php site and writes the > > resulting output to html files. this is necessary as the nature of the > > hosting available to me for this particular page prohibits me from using > > php/mysql as i would like.
> >
> > my script works simply by using output buffers and an include
> > the relevant section of code is as follows:
> >
> > ob_start();
> > include($source.$pagename);
> > $page_buffer = ob_get_contents();
> > ob_end_clean();
> >
> > i was wondering if there is a way i can do this without using the
include,
> > because the script only works when it is in the same directory as the > site.
> > this arrangement does not suit me, as i would rather be able to store the
> > script in a separate folder.
> >
> >
> >
> >
> >
> My first thought is to create an array with your directory names that you > want to scan
>
> $allDirs =
>
array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac > he/site1/htdocs") etc...
>
> then iterate through the array and subsequent directory files.
>
> while (list(,$dirName) = each($allDirs) {
> // create an array of all files
> $allFiles = scandir($dirName);
> while (list ($key,$fileName) = each($allFiles) {
> // each file within each directory
> $page_buffer to $fileName stuf......
> }
> }
>
>
perhaps i havent been clear enough
i dont want to use includes to perform this task. i would like to get the html output of a php script that is quite complicated and uses a variety of includes of its own which i do not wish to rewrite unless i absolutely have to. these includes are disturbed when my script resides in a different
directory to the page.

as it stands, the script works. it just isnt an ideal solution.
i am looking for something along the lines of the exec() command, only for executing php scripts.


I'm not sure I understand your problem, but if you want to execute php

scripts
on Linux, you can use

/pathinfo/php -q /pathinfo/scriptname.php

from the command line or a cron job. The "-q" suppresses HTTP headers.

Or you
could do:

/pathinfo/php -q /pathinfo/scriptname.php > index.html

to send all output from that php script to a file called index.html. Be

careful
with this, though, as it's easy to overwrite the wrong files...

this is *almost* what im looking for
trouble is, im running a windoze XP box.... is there any way to do the
'greater than' output to file thing in windoze?
and the other trouble is that if i want to perform that action from a php
script i have to use 'exec', which is not ideal if i want to move the script
to a *nix server some time in the future (which is highly likely)

the biggest issue is that running the script from any directory other than
the directory in which the page to export resides plays merry havoc with the
document relative paths in the script.
perhaps i should clarify - i have an entire website designed in php, built
off a mysql database, complete with a stack of includes and images and
what-have-you. the problem is that the hosting available to the organisation
that the website is for decided to pull the pin on their previous hosting
plan and are not willing to shell the extra $ for php/mysql hosting. my idea
then was to create this script which parses every single php page it can
become aware of (i had to adjust the databases and scrips a little bit to
respond to a $htmldump flag) and then creates new page names based on
obvious content. it then creates a table of all of the pages it created and
what those pages were created from... say for eg:
"page.php?frame=listbuild.php&hw_type=printers " becomes "printerslist.htm".
the script then looks through ALL of the newly created html pages for links
that belong to the old php site and updates them to the corresponding html
link, as well as copying other files and folders to recreate the site
structure.

the way the script is designed (and i might add that although it is
functional it is one piss poor piece of programming and i am embarrassed to
show it to people) is such that it MUST reside in the same directory as the
website it is dumping. i can see no other way to do it with output buffers
and includes (as i have been doing) without rewriting the entire website to
take into account the relocation of the output script. i REALLY do not want
to do this.

thank you very much for the reply though. i will definitely investigate
whether this will work as a band-aid solution.


Could you make your script write a <base href="http://yoursite.com/pathinfo">
into the <head> of each file?

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #8

P: n/a
youre forgetting - it needs to be OS independent

"Dag Sunde" <da******@orion.no.way> wrote in message
news:PI*********************@juliett.dax.net...

"Sticks Random" <ba***********@hotmail.com> wrote in message
news:3f**********************@freenews.iinet.net.a u...
this is *almost* what im looking for
trouble is, im running a windoze XP box.... is there any way to do the
'greater than' output to file thing in windoze?
and the other trouble is that if i want to perform that action from a php script i have to use 'exec', which is not ideal if i want to move the

script
to a *nix server some time in the future (which is highly likely)


This is cut from another post by Nikolai Chuvakhin here in this NG:

"
Spawn your asynchronous process via an exec() call with background
execution (& operator; Unix only). Examples:

exec ('myprogram &');
// executes a standalone program in the background

exec ('wget http://server.com/path/script.php --quiet -O /dev/null &');
// executes a PHP script in the background
// via the standard interface

exec ('php /path/script.php &');
// executes a PHP script in the background
// via command-line interface
"

Won't that work for you on a *nix box?

<snipped>

--
Dag.

Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.