php-general Digest 2 Jan 2006 15:24:41 -0000 Issue 3883

Topics (messages 228075 through 228087):

To copy a file from one server to another server in php
        228075 by: suma parakala
        228076 by: Michael Hulse
        228078 by: Michael Hulse

XML to PDF
        228077 by: Binay

How to check if an object is empty in PHP5
        228079 by: Mathijs
        228080 by: Jochem Maas

AT / php / apache question
        228081 by: david blunkett
        228082 by: Michael Gross

Reverse destruction
        228083 by: Mattias Segerdahl
        228084 by: Jochem Maas

Re: Which is faster, a MySQL access, or a set of PHP variables?
        228085 by: Dave M G
        228086 by: Al

Re: manipulating constant name as string
        228087 by: Al

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi
Can anyone tell me how can we copy one file from one server to another server using PHP
Thanks
Suma

_________________________________________________________________
Spice up your IM conversations. New, colorful and animated emoticons. Get chatting! http://server1.msn.co.in/SP05/emoticons/
--- End Message ---
--- Begin Message ---
Hello,

On Jan 2, 2006, at 12:27 AM, suma parakala wrote:
Hi
Can anyone tell me how can we copy one file from one server to another server using PHP
Thanks
Suma

I use this function to grab mp3's from one server and place them on another (transfers 10mb files rather nicely):

function grab_mp3($in, $out) {

        $remote = fopen($in, 'r');
        # Remember to chmod download folder to 777:
        $local = fopen('test/'.$out, 'w+');
        if(!$remote) {
                // handle failed request here ...
                echo "Oops!";
        }
        else {
                while (!feof($remote)) {
                        # Use @ to supress warning messages:
                        @$a .= fread($remote, 8192);
                }
        }
        fwrite($local, $a);
        
        fclose($remote);
        fclose($local);

        # Bye bye.

}

You could also use cURL:

http://us3.php.net/curl

Hth,
Cheers,
Micky

--- End Message ---
--- Begin Message ---
On Jan 2, 2006, at 12:32 AM, Michael Hulse wrote:
You could also use cURL:

From the cURL manual (in a terminal window type "man curl", without the quotes):

        ...
        ...
        -o/--output <file>
Write output to <file> instead of stdout. If you are using {} or [] to fetch multiple documents, you can use '#' followed by a number in the <file> specifier. That variable will be replaced with the current string for the URL being fetched. Like in:

                curl http://{one,two}.site.com -o "file_#1.txt"

              or use several variables like:

                curl http://{site,host}.host[1-5].com -o "#1_#2"

You may use this option as many times as you have number of
              URLs.

       -O/--remote-name
Write output to a local file named like the remote file we get. (Only the file part of the remote file is used, the path is cut
              off.)

You may use this option as many times as you have number of
              URLs.
        ...
        ...

--- End Message ---
--- Begin Message ---
Hi ALL

My applications requires converting XML file to PDF using PHP. Some surfing on 
the net revealed that it has to be first transformed to XSLT and then XSL:FO 
and finally to PDF . But i have no idea as where to start from. Confused and 
need directions or references to tutorials / resources which can shade lights 
on the inputs required. 

Thanks in advance.

Binay

--- End Message ---
--- Begin Message ---
Hello ppl,

How can i check if an Object is empty in PHP5?
Becouse empty() doesn't work.
Quote: "As of PHP 5, objects with no properties are no longer considered empty.".

Thx in advanced.

--- End Message ---
--- Begin Message ---
Mathijs wrote:
Hello ppl,

How can i check if an Object is empty in PHP5?
Becouse empty() doesn't work.
Quote: "As of PHP 5, objects with no properties are no longer considered empty.".

try:

class Test {}
$obj = new Test;
$arr = (array) $obj;
var_dump( empty($obj), empty($arr) );


Thx in advanced.


--- End Message ---
--- Begin Message ---

Dear PHP users,

I am trying to write a php script that allows me to schedule jobs using the at deamon (unix) for execution in the arbitrary future. I have everything working except that the default login shell for apache (nologin)
means that the at deamon fails to execute the command.

If I run the at command as another (not apache) user or change the apache login script to bash then
everything works fine.

I understand the nologin shell is a security feature for the apache account so i am reluctant to change it. AT is supposed to use the shell defined by the SHELL environment variable at the time of job submission but this does not appear to work in this case. I have tried wrapping the command in a setuid script to use another user id to side step this but I think
scripts are prevented from using setuid.
I could sidestep this by making a setuid executable but this seems like a desperate measure and that there should be a more sensible way of achieving this safely.

So does anyone have any suggestions? since "at" is a common word looking for solutions on the web
is rather difficult...

Cheers,

SA

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement
--- End Message ---
--- Begin Message ---
Hi
You could call the script via the http-server with wget (or lynx).


david blunkett wrote:

Dear PHP users,

I am trying to write a php script that allows me to schedule jobs using the at deamon (unix) for execution in the arbitrary future. I have everything working except that the default login shell for apache (nologin)
means that the at deamon fails to execute the command.

If I run the at command as another (not apache) user or change the apache login script to bash then
everything works fine.

I understand the nologin shell is a security feature for the apache account so i am reluctant to change it. AT is supposed to use the shell defined by the SHELL environment variable at the time of job submission but this does not appear to work in this case. I have tried wrapping the command in a setuid script to use another user id to side step this but I think
scripts are prevented from using setuid.
I could sidestep this by making a setuid executable but this seems like a desperate measure and that there should be a more sensible way of achieving this safely.

So does anyone have any suggestions? since "at" is a common word looking for solutions on the web
is rather difficult...

Cheers,

SA

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement


--- End Message ---
--- Begin Message ---
Is it possible to reverse class __destruct() instead of following the class
initiations? It makes more sence to me to close objects in last start first
close.

<?php
class Class1 {
        function __construct() {
                echo 'Constructing ' . __CLASS__ . "\n";
        }

        Function __destruct() {
                echo 'Destructing ' . __CLASS__ . "\n";
        }
}

class Class2 {
        function __construct() {
                echo 'Constructing ' . __CLASS__ . "\n";
        }

        Function __destruct() {
                echo 'Destructing ' . __CLASS__ . "\n";
        }
}

class Class3 {
        function __construct() {
                echo 'Constructing ' . __CLASS__ . "\n";
        }

        Function __destruct() {
                echo 'Destructing ' . __CLASS__ . "\n";
        }
}

$Class1 = new Class1();
$Class2 = new Class2();
$Class3 = new Class3();
?>

Would output,

Constructing Class1
Constructing Class2
Constructing Class3
Destructing Class1
Destructing Class2
Destructing Class3

I'd like for it to do:

Constructing Class1
Constructing Class2
Constructing Class3
Destructing Class1
Destructing Class2
Destructing Class3 Constructing Class1
Constructing Class2
Constructing Class3
Destructing Class3
Destructing Class2
Destructing Class1

Destructing the last started object first

--- End Message ---
--- Begin Message ---
Mattias Segerdahl wrote:
Is it possible to reverse class __destruct() instead of following the class
initiations? It makes more sence to me to close objects in last start first
close.

why don't you go and read up on request shutdown issues and __destruct() -
there is plenty in the archives of the internals@lists.php.net mailing list;
it's many times more complex than you might imagine (imagine 2 'chicken & egg'
problems in tandem - oh and a solution is needed to handle circular references
properly so that object refcounts behave the way you would expect with regard to
triggering dtor functions). bottom line don't hold your breath if you want the
__destruct() and shutdown code/beahviour changed.

*
* tell us why do you want to control the descruction order of your objects?
* it might help someone offer a viable alternative
*

btw: stating a new post/thread by replying to an existing one is very bad
form - given that you have knowledge of ctors/dtors in php your skill
level is probably greta enough that you should know better ;-)



<?php
class Class1 {
        function __construct() {
                echo 'Constructing ' . __CLASS__ . "\n";
        }

        Function __destruct() {
                echo 'Destructing ' . __CLASS__ . "\n";
        }
}

class Class2 {
        function __construct() {
                echo 'Constructing ' . __CLASS__ . "\n";
        }

        Function __destruct() {
                echo 'Destructing ' . __CLASS__ . "\n";
        }
}

class Class3 {
        function __construct() {
                echo 'Constructing ' . __CLASS__ . "\n";
        }

        Function __destruct() {
                echo 'Destructing ' . __CLASS__ . "\n";
        }
}

$Class1 = new Class1();
$Class2 = new Class2();
$Class3 = new Class3();
?>

Would output,

Constructing Class1
Constructing Class2
Constructing Class3
Destructing Class1
Destructing Class2
Destructing Class3

I'd like for it to do:

Constructing Class1
Constructing Class2
Constructing Class3
Destructing Class1
Destructing Class2
Destructing Class3 Constructing Class1
Constructing Class2
Constructing Class3
Destructing Class3
Destructing Class2
Destructing Class1

Destructing the last started object first


--- End Message ---
--- Begin Message ---
        Thank you for the advice.
        The point was raised, and it's a good one, that if I'm getting content
from the database for most pages, then attaining the necessary
translations probably won't make a difference.
        And of course, it is true that at my current levels of hits, the server
load is negligible. But, of course, one always hopes that site
popularity will increase and justify the efforts of making it efficient.
        I think I am going to database the translations for now, and then later
if need be, I will go with the suggestions of creating a list of
variables from the database once a day with a cron job.

        I appreciate all the help people have given to let me understand the
issue.

--
Dave M G

--- End Message ---
--- Begin Message ---
Dave M G wrote:
        Thank you for the advice.
        The point was raised, and it's a good one, that if I'm getting content
from the database for most pages, then attaining the necessary
translations probably won't make a difference.
        And of course, it is true that at my current levels of hits, the server
load is negligible. But, of course, one always hopes that site
popularity will increase and justify the efforts of making it efficient.
        I think I am going to database the translations for now, and then later
if need be, I will go with the suggestions of creating a list of
variables from the database once a day with a cron job.

        I appreciate all the help people have given to let me understand the
issue.

--
Dave M G

If you are that concerned, I'd suggest making a test script with both 
approaches and measure the execution times.

The performance difference may depend on on the DB server performance. On a previous shared webhost, I found the mySQL server was incredibly slow, so simple files were much faster.
--- End Message ---
--- Begin Message ---
Tom Rogers wrote:
Hi,

Monday, January 2, 2006, 4:37:17 AM, you wrote:
DG> Hello

DG> I am trying to access the constant name as string and not the constant
DG> contents. For example,

DG> define('myconst', 'const text 1');

DG> $myArray = array()

DG> myArray['myconst'] = "this is it"
DG> etc.

DG> $xmltext="";
DG> foreach ($myArray as $key => $val) {
DG>     echo "$key = $val\n\n";
DG>     $xmltext .= "$xmltext = $xmltext . "<$key> $val </$key>";
DG> }

DG> Unfortunately, $key within the string concatenation is translated into
DG> the constant value. However, for the echo statement, then $key constant
DG> name is displayed. Is there a way to keep the constant name rather its
DG> value when manipulating it as a string?

DG> thanks,

DG> Daniel

drop the single quotes to use the constant:

myArray[myconst] = "this is it"

A suggestion..

Make it a habit to use all caps for your constants.  It makes little "gotchas" 
easier to spot.

e.g., define('MYCONST', 'const text 1');

Then your array would be obvious: myArray[MYCONST] = "this is it"; verses 
myArray['myconst'] = "this is it";

--- End Message ---

Reply via email to