php-general Digest 23 Jul 2005 06:49:32 -0000 Issue 3583
Topics (messages 219235 through 219247):
Re: gloabl & reference behavior question?
219235 by: Surendra Singhi
Re: Konqueror does not like my Website
219236 by: Rick Emery
Re: Is there a way to get a variable name as a string?
219237 by: Daevid Vincent
219238 by: Daevid Vincent
Re: how to post a question?
219239 by: Edward Vermillion
On register_shutdown_function: What might be the problem?
219240 by: Liang ZHONG
219241 by: André Medeiros
219242 by: Liang ZHONG
219243 by: Jasper Bryant-Greene
219246 by: Rasmus Lerdorf
219247 by: Liang ZHONG
Re: System specific information gathering
219244 by: Vidyut Luther
219245 by: Ramil Sagum
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 ---
"Richard Lynch" <[EMAIL PROTECTED]> writes:
> The & operator is not, as far as I know, defined for an array assignment
> operation.
>
> True, you can use & in the parameter list in some versions to keep PHP
> from copying the whole array. But that does not legitimatize what you are
> doing, I don't think.
I never claimed, what I was doing was correct, rather I didn't knew well
enough that 'PHP is not C++', and I was misunderstanding how reference and
global variables work in PHP.
>
> I could be 100% wrong. I've never even *TRIED* to use a reference to an
> array because I simply don't want to write code that confusing in the
> first place.
I don't think it will make the code confusing, but the person looking at the
code should understand how reference and global variables work. Using
reference variables avoids unnecessary extra copying of objects, and while
using large arrays it can make a big difference in speed.
The lesson to learn from this thread is that variables declared in a function
as global (using global keyword) are new reference variables to the actual
global variable. And, so when these global variables in functions are assigned
a new reference, it breaks the old reference and makes them refer to the new
location, and the actual global variable is not affected.
But in contrast, if the global variables in the function are assigned a new
value, this does changes the value of the variable in the outer global scope.
--
Surendra Singhi
http://www.spikesource.com
http://www.public.asu.edu/~sksinghi/
--- End Message ---
--- Begin Message ---
Quoting Michelle Konzack <[EMAIL PROTECTED]>:
Am 2005-07-22 10:12:17, schrieb John Nichel:
You mean the 'posting a totally non-php question to a php list' bug?
Because the page is generated by a couple of PHP scripts and
ONLY THIS PAGE is not working.
So I was thinking there is a problem with the file-extension
*.php and Konqueror can not handel this... (It is KDE 3.4)
Greetings
Michelle
I just opened it in Konqueror 3.4.1 to look for any javascript errors,
and it seemed to load and work fine.
Sorry I wasn't any help,
Rick
--
Rick Emery
"When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return"
-- Leonardo Da Vinci
--- End Message ---
--- Begin Message ---
> What I was thinking with debug_backtrace() is that you could get the
> information for the function that called the function you want the
> variable name for, *reducing* the likelyhood of duplicate values, but
> admitedly not eliminating it.
>
> You could also pass the name of the variable to the function:
>
> someFunction($foo, $varName=""){ print $varName; }
>
> call it with -> someFunction($bar, 'bar');
>
> That would definately get you what you want, but again it
> would be messy to look at.
Well if you called someFunction('bar');
Function someFunction($myVar)
{
global $$myVar;
echo "the variable name is '$myVar' and has the value of ".$$myVar;
}
But that relies on the global and is also a bit messy in a recursive
situation.
--- End Message ---
--- Begin Message ---
> He wants a function that, if you put in $x, you get out 'x'
>
> For *ANY* $variable.
>
> There is no such function.
> Usually the person asking it is doing something very
> newbie-ish, and very wrong.
Actually it's not either...
Since you can't easily debug when generating XML, as malformed XML will STB,
I have this function which dumps out an array and recursively sub arrays.
It would be very useful to dump out the name of the variable as part of
this, as a lot of text is on the screen with all the tags and such.
It always annoyed me about print_r() that it doesn't tell you the variable
name either, so you have to always prefix it with an echo/print just above
the print_r.
/**
* Print out an array in XML form (useful for debugging)
* @access public
* @param string $myArray the array to output in XML format
* @version 1.0
* @date 07/19/05
* @todo It would be nice if we could extract the array's variable
name and output that as an attribute
*/
function print_r_xml($myArray)
{
print xmltag('ARRAY', null, 1);
foreach($myArray as $k => $v)
{
if (is_array($v))
print_r_xml($v);
else
print xmltag($k,htmlspecialchars($v));
}
print xmltag('ARRAY', null, 2);
}
/**
* Add the starting, or ending, or both xml tags
*
* @return string xml formatted tags and data
* @param string $xmltag is the tag name to surround
* @param mixed $data data to output between the tags, if $data is
an array, it will be expanded as KEY=VALUE in the tag
* @param int $tagType 1=start tag only, 2=end tag only, 3=default
* @version 1.2
* @date 06/14/05
*/
function xmltag($xmltag, $data, $tagType = 3)
{
// remove spaces and make uppercase
$xmltag = str_replace(' ','_', $xmltag );
//$xmltag = strtoupper( $xmltag );
$data = str_replace('&','&', $data ); // fix data with &
$data = str_replace('<','<', $data ); // fix data with <
$data = str_replace('>','>', $data ); // fix data with >
if ($tagType == 3)
{
if (isset($data))
{
if (is_array($data))
{
$tmp = '<'.$xmltag;
if (is_array($data))
{
foreach($data as $key => $value)
$tmp .= '
'.$key.'="'.$value.'"';
}
$tmp .= " />\r\n";
return $tmp;
}
else
return
'<'.$xmltag.'>'.$data.'</'.$xmltag.">\r\n";
}
else
return '<'.$xmltag." />\r\n";
}
if ($tagType == 1)
{
$tmp = '<'.$xmltag;
if (is_array($data))
{
foreach($data as $key => $value)
$tmp .= ' '.$key.'="'.$value.'"';
}
$tmp .= ">\r\n";
return $tmp;
}
if ($tagType == 2) return '</'.$xmltag.">\r\n";
}
--- End Message ---
--- Begin Message ---
Chirantan Ghosh wrote:
Hello Edward,
I did try your approach in this page
http://www.homecare1.biz/public_html/PHPsiteTest01.html with no avail.
How would I find out if I have fopen wrappers enabled?
This page is remote hosted ( Hosted by Godaddy.com who state I have
PHP/MySQL enabled).
CODE USED:
===========
<table width="778" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
All you need to have in the page is this code:
<?php
print
htmlentities(file_get_contents('http://www.dtcc.com/ThoughtLeadership/menu.htm'));
?>
you don't need this either:
</td>
</tr>
<tr>
============
Thanks for the help,
Chirantan
Since it's a remote server, it's quite lilely that they've disabled
fopen wrappers. It can be a security concern for hosting providers. All
you can do is ask them if they allow it, they should be able to tell you
but I really doubt that they do.
You can check what they have configured php for by running this in a page:
<?php
phpinfo();
?>
That should give you a pretty page with a lot of information about what
is available for you to run through php.
Good luck!
--- End Message ---
--- Begin Message ---
<?php
set_time_limit(0);
function f(){
$count=10000000;
for($i=0; $i<$count; $i++){ }
exec("touch /tmp/ccc");
}
register_shutdown_function('f');
header("Content-type: text/plain");
header("Location: y.html");
?>
When the time_limit is set to 0, the redirect page will be shown in 20
second after the file ccc is created.
When the time_limit is set to 5, the redirect page will be shown in 5 second
and the ccc file is not created. The error from curl command line tool is
as:
---------------------------------------
<br />
<b>Fatal error</b>: Maximum execution time of 5 seconds exceeded
in<b>/...../y.php</b> on line <b>6</b><br />
----------------------------------------
What might be the problem that my register shudown function can not
continuously run after the main program end?
What is the correct way to keep the function running after I redirect a
existing page to http client and then immediately close the connection?
Thank you very much for your help.
--- End Message ---
--- Begin Message ---
Given it's a fatal error, it's as bad as a syntax error. It cancels
everything it's doing and leaves.
Remember that, even the shutdown function has to obey the time limit.
On 7/22/05, Liang ZHONG <[EMAIL PROTECTED]> wrote:
> <?php
>
> set_time_limit(0);
> function f(){
> $count=10000000;
> for($i=0; $i<$count; $i++){ }
>
> exec("touch /tmp/ccc");
> }
>
>
> register_shutdown_function('f');
>
> header("Content-type: text/plain");
> header("Location: y.html");
> ?>
>
>
> When the time_limit is set to 0, the redirect page will be shown in 20
> second after the file ccc is created.
> When the time_limit is set to 5, the redirect page will be shown in 5 second
> and the ccc file is not created. The error from curl command line tool is
> as:
> ---------------------------------------
> <br />
> <b>Fatal error</b>: Maximum execution time of 5 seconds exceeded
> in<b>/...../y.php</b> on line <b>6</b><br />
> ----------------------------------------
>
> What might be the problem that my register shudown function can not
> continuously run after the main program end?
> What is the correct way to keep the function running after I redirect a
> existing page to http client and then immediately close the connection?
>
> Thank you very much for your help.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
I want the http client see the page ( here y.html) immediately after I call
header function, and then close the connectiion, and the function f running
in the background. But trying many many times, the result seems that I have
to either set the time limit to small to send the the html page sooner but
also terminate the background running function which was registered as a
shutdown function, or set the time to long enough for the shutdown function
to finish while keeping the http client waiting until function return.
I doubt that register_shutdown_function meant to behave this way by its
design. I would like to find out what could be wrong of my code,
configuration of php or apache?
My Question is:
What is the correct way to keep the function running after I redirect an
existing page to http client (which I want the client get immediately) and
then immediately close the connection?
Thank you very much.
Given it's a fatal error, it's as bad as a syntax error. It cancels
everything it's doing and leaves.
Remember that, even the shutdown function has to obey the time limit.
On 7/22/05, Liang ZHONG <[EMAIL PROTECTED]> wrote:
> <?php
>
> set_time_limit(0);
> function f(){
> $count=10000000;
> for($i=0; $i<$count; $i++){ }
>
> exec("touch /tmp/ccc");
> }
>
>
> register_shutdown_function('f');
>
> header("Content-type: text/plain");
> header("Location: y.html");
> ?>
>
>
> When the time_limit is set to 0, the redirect page will be shown in 20
> second after the file ccc is created.
> When the time_limit is set to 5, the redirect page will be shown in 5
second
> and the ccc file is not created. The error from curl command line tool
is
> as:
> ---------------------------------------
> <br />
> <b>Fatal error</b>: Maximum execution time of 5 seconds exceeded
> in<b>/...../y.php</b> on line <b>6</b><br />
> ----------------------------------------
>
> What might be the problem that my register shudown function can not
> continuously run after the main program end?
> What is the correct way to keep the function running after I redirect a
> existing page to http client and then immediately close the connection?
>
> Thank you very much for your help.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Liang ZHONG wrote:
What is the correct way to keep the function running after I redirect an
existing page to http client (which I want the client get immediately)
and then immediately close the connection?
Use the execution functions to call an external script that performs the
tasks you want performed. If you execute, for example,
"/some/path/somescript &", then the exec() function will return
immediately and somescript will continue to run.
Jasper
--- End Message ---
--- Begin Message ---
Liang ZHONG wrote:
> My Question is:
> What is the correct way to keep the function running after I redirect an
> existing page to http client (which I want the client get immediately)
> and then immediately close the connection?
ignore_user_abort(true);
-Rasmus
--- End Message ---
--- Begin Message ---
I think I did not express myself clearly.
What I want is to be able to redirect user an existing page (let them get it
immediately), and to close the connection actively, NOT passively by user
abort, at last, to run the function in background.
But the redirecting using function header() with location has a problem that
header() always does return the page to user after the entire program,
including registered showdown function finish running, which is against the
will. I put a time consuming task into a function that registered to be a
shutdown function and hoping it runs after the user has got the redirected
page and the connection has been closed. But experiements (using browsers,
curl command line tool as well as perl::LWP code) show that the user got the
redirected page only after the shutdown function finished, which is against
the description of register_shutdown_function at php website.
It seems only header() function use to redirect page has this problem (not
executed until register_shutdown_function finished) while other functions
like print()/echo(), exec() have not.
The code looks like:
---------------------------------------------------------------------------------------------
<?php
set_time_limit(1);
function f(){
set_time_limit(20);
$count=50000000;
for($i=0; $i<$count; $i++){ }
echo "end";
exec("touch /home/.nappy/liang/liang.ns2user.info/php/aaa");
}
register_shutdown_function('f');
header("Content-type: text/plain");
header("Location: y.html");
?>
---------------------------------------------------------------------------------------------
http client who sends the request to the php program will only get the page
back as response after function f finsihes (file aaa created). Changing the
$count will make a lot difference.
My BIGGEST question is:
How to make user get the redirect page immediately after the header() is
called, and not until function f() ends, while making sure that the function
f() will finally fully (and might slowly) execute?
Thank you very much for kindly replying.
With high respect,
Liang
Liang ZHONG wrote:
> My Question is:
> What is the correct way to keep the function running after I redirect an
> existing page to http client (which I want the client get immediately)
> and then immediately close the connection?
ignore_user_abort(true);
-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Ok,
If I use the file_get_contents.. how do I actually parse the
contents on /proc/uptime
cat /proc/uptime
1400293.13 1317047.64
What do I do with those two numbers ?
man uptime doesn't really talk about that file.. :/
On Jul 22, 2005, at 2:42 AM, Jasper Bryant-Greene wrote:
Vidyut Luther wrote:
Hello,
I have a question on how to get Server side system specific
information via PHP, or just general direction on how to parse
some of the information found in /proc
I just use file_get_contents() on the files in /proc. I would
expect that would be a lot faster than using system() to execute
'uptime' etc.
Jasper
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On 7/23/05, Vidyut Luther <[EMAIL PROTECTED]> wrote:
> Ok,
> If I use the file_get_contents.. how do I actually parse the
> contents on /proc/uptime
> cat /proc/uptime
> 1400293.13 1317047.64
The first number is the total uptime in seconds, the second number is
the total idle time.
--
----
ramil
http://ramil.sagum.net/
--- End Message ---