php-general Digest 23 Jul 2008 09:21:54 -0000 Issue 5584

Topics (messages 277179 through 277186):

Re: [PHP-INSTALL] Executing a python script from within perl
        277179 by: Daniel Brown
        277180 by: Daniel Brown
        277181 by: Anuj Bhatt

Reference or copy?
        277182 by: Yeti
        277183 by: Robert Cummings
        277184 by: Ted Wood
        277185 by: Ted Wood

Getting info from SVN commit with php
        277186 by: Raido

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:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
    Forwarded to the appropriate list (PHP General).  Anuj: If you're
not already subscribed, please visit http://php.net/mailinglists and
subscribe to the PHP General list, or send a blank email to
[EMAIL PROTECTED]

On Tue, Jul 22, 2008 at 11:09 PM, Anuj Bhatt <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
> I'm new to PHP and just installed apache2 with php support. I'm trying
> to execute a Python script (from within php), which does take a good
> amount of time and am waiting for it to terminate so that I can process
> the output and print that out in HTML.
>
> The problem I'm having is that I can't get the PHP script to wait for
> the Python file to terminate. If I try it with a simple Python script
> say "print Hello, World!" it gets that. But anything that takes
> substantially long time, it just returns. I've tried system("myfile.py",
> $result) and $result results in a 1 and prints any subsequent prints in
> the PHP file. I also tried exec, with no luck. I've read through
> http://www.php.net/function.exec and the documentation presented in the
> "See Also" section with other commands. I haven't got anywhere yet,
> after much work. Any pointers, suggestions and fixes?

    Try this to see if your script is outputting any errors:

<?php
    exec('/path/to/python your-script.py 2>&1',$ret);
    print_r($ret);
?>

    If that works, you may just need to adjust your timeout and set
ignore_user_abort(1) to allow the Python script to keep running.  If
all else fails, and you're aware of the side-effects, go fork()
yourself.  ;-P

-- 
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
On Tue, Jul 22, 2008 at 11:27 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
>
> If all else fails, and you're aware of the side-effects, go fork() yourself.  
> ;-P

    For posterity:

        http://php.net/pcntl

    [See: pcntl_fork(), et al.]

-- 
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
On Tue, 2008-07-22 at 23:27 -0400, Daniel Brown wrote:
>     Try this to see if your script is outputting any errors:
> 
> <?php
>     exec('/path/to/python your-script.py 2>&1',$ret);
>     print_r($ret);
> ?>

This worked, was opening a file for which permission was denied. Python
didn't show me anything, when run on the prompt, however when I used the
above method, I did get the error. Thanks!


-anuj



--- End Message ---
--- Begin Message ---
Hello everyone,

Many of you may be familiar with references in PHP. Now i read
somewhere in the PHP manual that creating references can take longer
than copies. PHP5+ also seems to reference a bit different thant PHP4
did.
Here is some working example code:

<?php
class useless {
        var $huge_array;
        function __construct() {
                $this->huge_array = array();
                for ($i = 0; $i < 1024; $i++) $this->huge_array[] = $GLOBALS; //
fill ze array with copies of $GLOBALS array
                return true;
        }
        function useless() {
                return $this->__construct();
        }
}
$time_start = microtime(true);
$test_obj = new useless();
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds without using the reference operator.\r\n";
unset($test_obj);
$time_start = microtime(true);
$test_obj =& new useless();
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds using the reference
operator.\r\n########## with obj2 ############\r\n";
$time_start = microtime(true);
$test_obj = new useless();
$obj2 = $test_obj;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds without using the reference operator.\r\n";
unset($test_obj);
$time_start = microtime(true);
$test_obj =& new useless();
$obj2 =& $test_obj;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds using the reference operator.\r\n";
?>

I tested the code in PHP 4.4.7 and in PHP 5.2.5 and the results were
pretty much the same. Using references speeds up the script!
Occasionally obj2-with-references took longer than all the others. But
i don't know if that's to be taken serious.

Now if i do not need a copy, isn't it smarter to use references instead?

I'm grateful for any ideas, thoughts or experiences
Yeti

--- End Message ---
--- Begin Message ---
On Wed, 2008-07-23 at 10:07 +0200, Yeti wrote:
> Hello everyone,
> 
> Many of you may be familiar with references in PHP. Now i read
> somewhere in the PHP manual that creating references can take longer
> than copies. PHP5+ also seems to reference a bit different thant PHP4
> did.
> Here is some working example code:
> 
> <?php
> class useless {
>       var $huge_array;
>       function __construct() {
>               $this->huge_array = array();
>               for ($i = 0; $i < 1024; $i++) $this->huge_array[] = $GLOBALS; //
> fill ze array with copies of $GLOBALS array
>               return true;
>       }
>       function useless() {
>               return $this->__construct();
>       }
> }
> $time_start = microtime(true);
> $test_obj = new useless();
> $time_end = microtime(true);
> $time = $time_end - $time_start;
> echo "It took {$time} seconds without using the reference operator.\r\n";
> unset($test_obj);
> $time_start = microtime(true);
> $test_obj =& new useless();
> $time_end = microtime(true);
> $time = $time_end - $time_start;
> echo "It took {$time} seconds using the reference
> operator.\r\n########## with obj2 ############\r\n";
> $time_start = microtime(true);
> $test_obj = new useless();
> $obj2 = $test_obj;
> $time_end = microtime(true);
> $time = $time_end - $time_start;
> echo "It took {$time} seconds without using the reference operator.\r\n";
> unset($test_obj);
> $time_start = microtime(true);
> $test_obj =& new useless();
> $obj2 =& $test_obj;
> $time_end = microtime(true);
> $time = $time_end - $time_start;
> echo "It took {$time} seconds using the reference operator.\r\n";
> ?>
> 
> I tested the code in PHP 4.4.7 and in PHP 5.2.5 and the results were
> pretty much the same. Using references speeds up the script!
> Occasionally obj2-with-references took longer than all the others. But
> i don't know if that's to be taken serious.
> 
> Now if i do not need a copy, isn't it smarter to use references instead?
> 
> I'm grateful for any ideas, thoughts or experiences

In PHP4 if you don't need a copy then use a reference... it will be
faster. In PHP5 you don't get a copy unless you explicitly clone the
object. And so, in PHP5 assignment by value is faster than assignment by
reference. However, there may be the odd time you really want a
reference. PHP4 is dead though... so they say.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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

The general rules of thumb are --> don't use references unless you actually *want* a reference. And don't use references for performance reasons.

Under PHP 4, it's generally been recommended to use a reference operator when creating objects.

         $obj =& new Object();

PHP uses references internally until it's necessary to create a copy:

$a = array();

$a = $b;                // internally, $b is a reference to $a

$b[] = "chocolate"; // at this point, a copy is made, and $b is modified

So PHP waits until a copy is actually needed before it makes one. Explicitly making copies incurs overhead because of the concept of "reference counting". So again, don't use references for performance reasons.

~Ted




On 23-Jul-08, at 1:07 AM, Yeti wrote:

Hello everyone,

Many of you may be familiar with references in PHP. Now i read
somewhere in the PHP manual that creating references can take longer
than copies. PHP5+ also seems to reference a bit different thant PHP4
did.
Here is some working example code:

<?php
class useless {
        var $huge_array;
        function __construct() {
                $this->huge_array = array();
                for ($i = 0; $i < 1024; $i++) $this->huge_array[] = $GLOBALS; //
fill ze array with copies of $GLOBALS array
                return true;
        }
        function useless() {
                return $this->__construct();
        }
}
$time_start = microtime(true);
$test_obj = new useless();
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds without using the reference operator.\r \n";
unset($test_obj);
$time_start = microtime(true);
$test_obj =& new useless();
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds using the reference
operator.\r\n########## with obj2 ############\r\n";
$time_start = microtime(true);
$test_obj = new useless();
$obj2 = $test_obj;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds without using the reference operator.\r \n";
unset($test_obj);
$time_start = microtime(true);
$test_obj =& new useless();
$obj2 =& $test_obj;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took {$time} seconds using the reference operator.\r\n";
?>

I tested the code in PHP 4.4.7 and in PHP 5.2.5 and the results were
pretty much the same. Using references speeds up the script!
Occasionally obj2-with-references took longer than all the others. But
i don't know if that's to be taken serious.

Now if i do not need a copy, isn't it smarter to use references instead?

I'm grateful for any ideas, thoughts or experiences
Yeti

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

On 23-Jul-08, at 1:19 AM, Ted Wood wrote:

So PHP waits until a copy is actually needed before it makes one. Explicitly making copies incurs overhead because of the concept of "reference counting". So again, don't use references for performance reasons.


That should've been:  Explicitly making "references", not copies...

~Ted

--- End Message ---
--- Begin Message ---
Hi,

I would be very grateful if someone could point out some ways how to do the following:

I have an SVN server but I need to add some extra to commit message which PHP will get and use(for example use the parameters from commit message to change data on mysql database... (if commit messages first line has character *, then run sql query... "update tasks set some_row='OK' where...."
Currently important is:
1) Is it even possible to get commit messages text with php ? Since I can't find the file where commit messages are.
I only digged subversion docs for 'how to edit message'

Should, be possible(bot nut sure) to use commands: $ svn propedit -r N --revprop svn:log URL
$ svn propset -r N --revprop svn:log "new log message" URL

What I'd like to achieve is:
I'l' make page where I store all my tasks (for example "Need to add login function 
to test.php"). In MySQL, this task has got ID 1 and STATUS 0 which means it isn't 
done yet.

Then when I have that task done I start writing commit message where first line 
may look like this: 1|1
and rest of the lines will be regular commit message. Then there will be PHP 
script which checks that commit message and reads that line where I put 1|1 and 
understands that first number is task ID and second is STATUS and then run sql 
query like:
update tasks set STATUS=1 where ID=1;

So, seems impossible? For me, currently yes, since I haven't found any examples 
how to do it...but I know that nothing is impossible.

Raido



--- End Message ---

Reply via email to