running php script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sticks

    #1

    running php script?

    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.





  • Paul 'piz' Wellner Bou

    #2
    Re: running php script?

    Hi,
    [color=blue]
    > 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.[/color]

    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.

    Comment

    • Guest's Avatar

      #3
      Re: running php script?


      "Sticks" <sarcasmic_98@y ahoo.com> wrote in message
      news:3fde9f74$1 @usenet.per.par adox.net.au...[color=blue]
      > 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[/color]
      site.[color=blue]
      > this arrangement does not suit me, as i would rather be able to store the
      > script in a separate folder.
      >
      >
      >
      >
      >[/color]
      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($dirNam e);
      while (list ($key,$fileName ) = each($allFiles) {
      // each file within each directory
      $page_buffer to $fileName stuf......
      }
      }



      Comment

      • Sticks

        #4
        Re: running php script?

        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:XfqdnbU1EP quUEKi4p2dnA@co mcast.com...[color=blue]
        >
        > "Sticks" <sarcasmic_98@y ahoo.com> wrote in message
        > news:3fde9f74$1 @usenet.per.par adox.net.au...[color=green]
        > > 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[/color][/color]
        include,[color=blue][color=green]
        > > because the script only works when it is in the same directory as the[/color]
        > site.[color=green]
        > > this arrangement does not suit me, as i would rather be able to store[/color][/color]
        the[color=blue][color=green]
        > > script in a separate folder.
        > >
        > >
        > >
        > >
        > >[/color]
        > My first thought is to create an array with your directory names that you
        > want to scan
        >
        > $allDirs =
        >[/color]
        array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac[color=blue]
        > 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($dirNam e);
        > while (list ($key,$fileName ) = each($allFiles) {
        > // each file within each directory
        > $page_buffer to $fileName stuf......
        > }
        > }
        >
        >
        >[/color]


        Comment

        • Shawn Wilson

          #5
          Re: running php script?

          Sticks wrote:
          [re-ordered you post because top-posting is evil :o)][color=blue]
          > <xyzzy> wrote in message news:XfqdnbU1EP quUEKi4p2dnA@co mcast.com...[color=green]
          > >
          > > "Sticks" <sarcasmic_98@y ahoo.com> wrote in message
          > > news:3fde9f74$1 @usenet.per.par adox.net.au...[color=darkred]
          > > > 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[/color][/color]
          > include,[color=green][color=darkred]
          > > > because the script only works when it is in the same directory as the[/color]
          > > site.[color=darkred]
          > > > this arrangement does not suit me, as i would rather be able to store[/color][/color]
          > the[color=green][color=darkred]
          > > > script in a separate folder.
          > > >
          > > >
          > > >
          > > >
          > > >[/color]
          > > My first thought is to create an array with your directory names that you
          > > want to scan
          > >
          > > $allDirs =
          > >[/color]
          > array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac[color=green]
          > > 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($dirNam e);
          > > while (list ($key,$fileName ) = each($allFiles) {
          > > // each file within each directory
          > > $page_buffer to $fileName stuf......
          > > }
          > > }
          > >
          > >[/color]
          > 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.
          >[/color]

          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
          shawn@glassgian t.com

          Comment

          • Sticks Random

            #6
            Re: running php script?

            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=printer s" becomes "printerslist.h tm".
            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" <shawn@glassgia nt.com> wrote in message
            news:3FE07492.E C411FE6@glassgi ant.com...[color=blue]
            > Sticks wrote:
            > [re-ordered you post because top-posting is evil :o)][color=green]
            > > <xyzzy> wrote in message news:XfqdnbU1EP quUEKi4p2dnA@co mcast.com...[color=darkred]
            > > >
            > > > "Sticks" <sarcasmic_98@y ahoo.com> wrote in message
            > > > news:3fde9f74$1 @usenet.per.par adox.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[/color][/color][/color]
            the[color=blue][color=green][color=darkred]
            > > > > resulting output to html files. this is necessary as the nature of[/color][/color][/color]
            the[color=blue][color=green][color=darkred]
            > > > > hosting available to me for this particular page prohibits me from[/color][/color][/color]
            using[color=blue][color=green][color=darkred]
            > > > > 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[/color]
            > > include,[color=darkred]
            > > > > because the script only works when it is in the same directory as[/color][/color][/color]
            the[color=blue][color=green][color=darkred]
            > > > site.
            > > > > this arrangement does not suit me, as i would rather be able to[/color][/color][/color]
            store[color=blue][color=green]
            > > the[color=darkred]
            > > > > script in a separate folder.
            > > > >
            > > > >
            > > > >
            > > > >
            > > > >
            > > > My first thought is to create an array with your directory names that[/color][/color][/color]
            you[color=blue][color=green][color=darkred]
            > > > want to scan
            > > >
            > > > $allDirs =
            > > >[/color]
            > >[/color][/color]
            array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac[color=blue][color=green][color=darkred]
            > > > 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($dirNam e);
            > > > while (list ($key,$fileName ) = each($allFiles) {
            > > > // each file within each directory
            > > > $page_buffer to $fileName stuf......
            > > > }
            > > > }
            > > >
            > > >[/color]
            > > perhaps i havent been clear enough
            > > i dont want to use includes to perform this task. i would like to get[/color][/color]
            the[color=blue][color=green]
            > > html output of a php script that is quite complicated and uses a variety[/color][/color]
            of[color=blue][color=green]
            > > includes of its own which i do not wish to rewrite unless i absolutely[/color][/color]
            have[color=blue][color=green]
            > > 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[/color][/color]
            for[color=blue][color=green]
            > > executing php scripts.
            > >[/color]
            >
            > I'm not sure I understand your problem, but if you want to execute php[/color]
            scripts[color=blue]
            > on Linux, you can use
            >
            > /pathinfo/php -q /pathinfo/scriptname.php
            >
            > from the command line or a cron job. The "-q" suppresses HTTP headers.[/color]
            Or you[color=blue]
            > 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[/color]
            careful[color=blue]
            > with this, though, as it's easy to overwrite the wrong files...
            >
            > HTH,
            > Shawn
            > --
            > Shawn Wilson
            > shawn@glassgian t.com
            > http://www.glassgiant.com[/color]


            Comment

            • Dag Sunde

              #7
              Re: running php script?


              "Sticks Random" <barton_finkle@ hotmail.com> wrote in message
              news:3fe0e4b4$0 $1734$5a62ac22@ freenews.iinet. net.au...[color=blue]
              > 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[/color]
              script[color=blue]
              > to a *nix server some time in the future (which is highly likely)
              >[/color]

              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.


              Comment

              • Shawn Wilson

                #8
                Re: running php script?

                Sticks Random wrote:[color=blue]
                >[/color]
                [Post moved to bottom because top-posting is evil :o) ][color=blue]
                > "Shawn Wilson" <shawn@glassgia nt.com> wrote in message
                > news:3FE07492.E C411FE6@glassgi ant.com...[color=green]
                > > Sticks wrote:
                > > [re-ordered you post because top-posting is evil :o)][color=darkred]
                > > > <xyzzy> wrote in message news:XfqdnbU1EP quUEKi4p2dnA@co mcast.com...
                > > > >
                > > > > "Sticks" <sarcasmic_98@y ahoo.com> wrote in message
                > > > > news:3fde9f74$1 @usenet.per.par adox.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[/color][/color]
                > the[color=green][color=darkred]
                > > > > > resulting output to html files. this is necessary as the nature of[/color][/color]
                > the[color=green][color=darkred]
                > > > > > hosting available to me for this particular page prohibits me from[/color][/color]
                > using[color=green][color=darkred]
                > > > > > 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[/color][/color]
                > the[color=green][color=darkred]
                > > > > site.
                > > > > > this arrangement does not suit me, as i would rather be able to[/color][/color]
                > store[color=green][color=darkred]
                > > > the
                > > > > > script in a separate folder.
                > > > > >
                > > > > >
                > > > > >
                > > > > >
                > > > > >
                > > > > My first thought is to create an array with your directory names that[/color][/color]
                > you[color=green][color=darkred]
                > > > > want to scan
                > > > >
                > > > > $allDirs =
                > > > >
                > > >[/color][/color]
                > array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac[color=green][color=darkred]
                > > > > 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($dirNam e);
                > > > > 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[/color][/color]
                > the[color=green][color=darkred]
                > > > html output of a php script that is quite complicated and uses a variety[/color][/color]
                > of[color=green][color=darkred]
                > > > includes of its own which i do not wish to rewrite unless i absolutely[/color][/color]
                > have[color=green][color=darkred]
                > > > 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[/color][/color]
                > for[color=green][color=darkred]
                > > > executing php scripts.
                > > >[/color]
                > >
                > > I'm not sure I understand your problem, but if you want to execute php[/color]
                > scripts[color=green]
                > > on Linux, you can use
                > >
                > > /pathinfo/php -q /pathinfo/scriptname.php
                > >
                > > from the command line or a cron job. The "-q" suppresses HTTP headers.[/color]
                > Or you[color=green]
                > > 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[/color]
                > careful[color=green]
                > > with this, though, as it's easy to overwrite the wrong files...[/color]
                > 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=printer s" becomes "printerslist.h tm".
                > 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.[/color]

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

                Regards,
                Shawn
                --
                Shawn Wilson
                shawn@glassgian t.com

                Comment

                • Sticks Random

                  #9
                  Re: running php script?

                  youre forgetting - it needs to be OS independent

                  "Dag Sunde" <dag.nope@orion .no.way> wrote in message
                  news:PI5Eb.2866 9$BD3.5731238@j uliett.dax.net. ..[color=blue]
                  >
                  > "Sticks Random" <barton_finkle@ hotmail.com> wrote in message
                  > news:3fe0e4b4$0 $1734$5a62ac22@ freenews.iinet. net.au...[color=green]
                  > > 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[/color][/color]
                  php[color=blue][color=green]
                  > > script i have to use 'exec', which is not ideal if i want to move the[/color]
                  > script[color=green]
                  > > to a *nix server some time in the future (which is highly likely)
                  > >[/color]
                  >
                  > 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.
                  >
                  >[/color]


                  Comment

                  Working...