php-general Digest 12 Mar 2009 13:47:54 -0000 Issue 6007
Topics (messages 289912 through 289921):
Re: PHP/Apache: script unexpectedly invoked multiple times in parallel every 30
secs.
289912 by: Nathan Rixham
289913 by: Michael A. Peters
Re: Working directory of PHP pages?
289914 by: Clancy
289915 by: 9el
289920 by: haliphax
Re: Silly question - include vs. eval
289916 by: Robert Cummings
PHP 5.2.9 - 5.2.9-1 and curl
289917 by: Niki
Re: built-in objects APC or serializationþ
289918 by: Andrea Giammarchi
Re: Include File Errors with Comments
289919 by: Andrew Ballard
Re: ltrim behavior.
289921 by: tedd
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 ---
Marc Venturini wrote:
Hi all,
Thank you all very much for your contributions.
I tried to monitor the network with Wireshark: there is only one request
from my browser to the server, and not any answer (redirect or otherwise).
This means the problem is definitely not with unexpected browser requests.
Calling die() at the end of the script and removing the redirect did not
change the behavior in any way.
I like to think my code is good, and that the server calls the script in an
unexpected way. The main reason for this belief is that I do not use
multithreading at all, while the logs report the script is running several
times in parallel and the network monitor reports a single browser request.
I could not find in the docs any server configuration parameter which would
re-invoke a script without killing its currently running instance.
are you forking the script at all? if so you can't unless on the cli
--- End Message ---
--- Begin Message ---
Nathan Rixham wrote:
Marc Venturini wrote:
Hi all,
Thank you all very much for your contributions.
I tried to monitor the network with Wireshark: there is only one request
from my browser to the server, and not any answer (redirect or
otherwise).
This means the problem is definitely not with unexpected browser
requests.
Calling die() at the end of the script and removing the redirect did not
change the behavior in any way.
I like to think my code is good, and that the server calls the script
in an
unexpected way. The main reason for this belief is that I do not use
multithreading at all, while the logs report the script is running
several
times in parallel and the network monitor reports a single browser
request.
I could not find in the docs any server configuration parameter which
would
re-invoke a script without killing its currently running instance.
are you forking the script at all? if so you can't unless on the cli
I don't know what is causing it, but is the site live? If so, could it
be a proxy somewhere re-requesting the data when it thinks your server
has timed out? I guess you ruled that out with the wireshark.
If it really takes over 30 seconds to process the images, would it
better to just have your script cue the images and exit, with
ImageMagick running on the server to do the actual hard work?
Write a shell script that cron runs every 5 minutes.
The script wgets a shell script from your server with the cue of what
needs to be processed and then processes it.
I don't know for sure, but I suspect using ImageMagick in a shell script
is going to be less resource intensive than the web server doing it.
Doing it that way lets your script exit much sooner and would avoid
impatient user reloads, which could be a problem even when you do figure
out this issue.
I almost wonder if Apache has some directive that tries to serve the
data again if it thinks there was a backend problem with it's first request.
What happens when you try to request your page with wget or lynx?
They won't try to load any images, so if there is a image src problem
that should make it obvious.
--- End Message ---
--- Begin Message ---
On Wed, 11 Mar 2009 13:03:19 -0500, [email protected] (haliphax) wrote:
>On Wed, Mar 11, 2009 at 12:44 PM, Shawn McKenzie <[email protected]> wrote:
>> Clancy wrote:
>>> It is my understanding that when you open a page the PHP server looks for
>>> index.php in the
>>> site root directory, and loads it. As a result the working directory of the
>>> page will be
>>> the root directory of the site. I have always worked on this assumption,
>>> and it has
>>> always been correct. On the other hand Stewart thinks that I cannot rely
>>> this, and am
>>> likely to get into trouble as a result.
>>>
>>> Are there any systems in which my assumption will not be correct?
>>>
>>
>> In many frameworks this assumption is not correct. I am using the
>> default CakePHP layout as an example.
>>
>> Depending on your terminology, your DocumentRoot is /var/www/ and in
>> this case is also the filesystem path of your site's root dir, however
>> the sites root dir in a URL is /.
>>
>> Consider the CakePHP structure:
>>
>> /var/www/
>> .htaccess
>> index.php
>> /var/www/webroot
>> index.php
>>
>> If you browse to http://example.com/ (in most cases), one of 2 things
>> happens:
>>
>> 1. The webserver opens the /var/www/.htaccess and according to the
>> rewrite rules there it rewrites to /var/www/webroot/. So any getcwd()
>> would be /var/www/webroot/
>>
>> 2. If not using modrewrite, the web server looks for index.html and then
>> index.php in /var/www/ which has a require for webroot/index.php. So
>> any getcwd() would be /var/www/.
>>
>> Consequently, CakePHP and the other frameworks that I've seen use
>> basename() and dirname() in conjunction with __FILE__ to define the
>> paths/relative dirs within the app.
>
>Come to think of it, this may very well be true for all MVC frameworks
>(unless the models, views, and controllers are all in the same
>directory as the launch script). I can at least vouch for the fact
>that CodeIgniter, like CakePHP, will fudge your directory estimation
>if you're expecting getcwd() to be right.
Something Stewart said the other day made me realise that there was a
fundamental error in
the way I was thinking about this question. I had been thinking that opendir
(.) opened
the root directory, and that paths such as Joe/Nurg.com were relative to the
root
directory, but I now realise that they are relative to the current directory,
whatever
that might be. (Yes; I should have known better, but there is an awful swamp of
burnt out
brain cells at the bottom of my brain.)
So the question I should have asked was "When a web page is loaded, can I rely
on the CWD
being the directory containing index.php (or whichever file is actually
loaded)?"
Thank you all for your assistance.
--- End Message ---
--- Begin Message ---
On Thu, Mar 12, 2009 at 11:47 AM, Clancy <[email protected]> wrote:
>
> Something Stewart said the other day made me realise that there was a
> fundamental error in
> the way I was thinking about this question. I had been thinking that
> opendir (.) opened
> the root directory, and that paths such as Joe/Nurg.com were relative to
> the root
> directory, but I now realise that they are relative to the current
> directory, whatever
> that might be. (Yes; I should have known better, but there is an awful
> swamp of burnt out
> brain cells at the bottom of my brain.)
a dot (.) denotes a current directory and double dot (..) denotes parent
directory of the current in DOS/Windows/*nix File System.
>
>
> So the question I should have asked was "When a web page is loaded, can I
> rely on the CWD
> being the directory containing index.php (or whichever file is actually
> loaded)?"
>
> Thank you all for your assistance.
>
>
>
--- End Message ---
--- Begin Message ---
On Thu, Mar 12, 2009 at 12:47 AM, Clancy <[email protected]> wrote:
> On Wed, 11 Mar 2009 13:03:19 -0500, [email protected] (haliphax) wrote:
>
>>On Wed, Mar 11, 2009 at 12:44 PM, Shawn McKenzie <[email protected]> wrote:
>>> Clancy wrote:
>>>> It is my understanding that when you open a page the PHP server looks for
>>>> index.php in the
>>>> site root directory, and loads it. As a result the working directory of
>>>> the page will be
>>>> the root directory of the site. I have always worked on this assumption,
>>>> and it has
>>>> always been correct. On the other hand Stewart thinks that I cannot rely
>>>> this, and am
>>>> likely to get into trouble as a result.
>>>>
>>>> Are there any systems in which my assumption will not be correct?
>>>>
>>>
>>> In many frameworks this assumption is not correct. I am using the
>>> default CakePHP layout as an example.
>>>
>>> Depending on your terminology, your DocumentRoot is /var/www/ and in
>>> this case is also the filesystem path of your site's root dir, however
>>> the sites root dir in a URL is /.
>>>
>>> Consider the CakePHP structure:
>>>
>>> /var/www/
>>> .htaccess
>>> index.php
>>> /var/www/webroot
>>> index.php
>>>
>>> If you browse to http://example.com/ (in most cases), one of 2 things
>>> happens:
>>>
>>> 1. The webserver opens the /var/www/.htaccess and according to the
>>> rewrite rules there it rewrites to /var/www/webroot/. So any getcwd()
>>> would be /var/www/webroot/
>>>
>>> 2. If not using modrewrite, the web server looks for index.html and then
>>> index.php in /var/www/ which has a require for webroot/index.php. So
>>> any getcwd() would be /var/www/.
>>>
>>> Consequently, CakePHP and the other frameworks that I've seen use
>>> basename() and dirname() in conjunction with __FILE__ to define the
>>> paths/relative dirs within the app.
>>
>>Come to think of it, this may very well be true for all MVC frameworks
>>(unless the models, views, and controllers are all in the same
>>directory as the launch script). I can at least vouch for the fact
>>that CodeIgniter, like CakePHP, will fudge your directory estimation
>>if you're expecting getcwd() to be right.
>
> Something Stewart said the other day made me realise that there was a
> fundamental error in
> the way I was thinking about this question. I had been thinking that opendir
> (.) opened
> the root directory, and that paths such as Joe/Nurg.com were relative to the
> root
> directory, but I now realise that they are relative to the current directory,
> whatever
> that might be. (Yes; I should have known better, but there is an awful swamp
> of burnt out
> brain cells at the bottom of my brain.)
>
> So the question I should have asked was "When a web page is loaded, can I
> rely on the CWD
> being the directory containing index.php (or whichever file is actually
> loaded)?"
I believe the answer was "No, not really," from several different people.
--
// Todd
--- End Message ---
--- Begin Message ---
On Wed, 2009-03-11 at 19:50 -0500, Shawn McKenzie wrote:
> Robert Cummings wrote:
> > On Wed, 2009-03-11 at 16:16 -0500, Shawn McKenzie wrote:
> >> Shawn McKenzie wrote:
> >>> Robert Cummings wrote:
> >>>> On Wed, 2009-03-11 at 13:20 -0500, Shawn McKenzie wrote:
> >>>>> Robert Cummings wrote:
> >>>>>> On Wed, 2009-03-11 at 12:19 -0500, Shawn McKenzie wrote:
> >>>>>>> Sándor Tamás (HostWare Kft . ) wrote:
> >>>>>>>> Yes, Rob is right. My original question is about the difference
> >>>>>>>> between
> >>>>>>>> the processing of a file-based site with include() OR eval(). In that
> >>>>>>>> case, if I understood it correctly, the results are the same.
> >>>>>>>>
> >>>>>>>> But! If the included pages contain functions, classes, etc. With
> >>>>>>>> eval(),
> >>>>>>>> can I use them? With include(), I know I should be able to use them.
> >>>>>>>> But
> >>>>>>>> in some mysterious cases I don't have access to a function. If I cut
> >>>>>>>> out
> >>>>>>>> from the included file, and put in on the file which includes that,
> >>>>>>>> just
> >>>>>>>> before (or after) the includ(), I don't have any problem with it.
> >>>>>>>>
> >>>>>>>> The next step, that if I include a file in a function, can I use the
> >>>>>>>> functions wrote in the included file?
> >>>>>>>> As I know, include just makes a copy-paste, so if I use it IN a
> >>>>>>>> function, then all function will be in function scope, am I right?
> >>>>>>> Yes, if you use an include inside a function, then any functions / non
> >>>>>>> global vars in the included file will only be available inside the
> >>>>>>> including function.
> >>>>>> This is NOT, I repeat, NOT true for functions. Functions are ALWAYS
> >>>>>> global.
> >>>>>>
> >>>>>> Cheers,
> >>>>>> Rob.
> >>>>> Yes, I was too hasty. The nested function will only be defined once the
> >>>>> nesting function has been called. Then it will be available globally.
> >>>> Actually, you're wrong again. The nested function, AKA function defined
> >>>> in the included source, will be defined as soon as the source is
> >>>> included and is available to the function in which the source was
> >>>> included. In fact it is even available to the code within the included
> >>>> source that can be run during the include process and before the
> >>>> function performing the inclusion regains control.
> >>>>
> >>>> Cheers,
> >>>> Rob.
> >>> Well I used the word defined, however what I meant was the included
> >>> function would only be available globally after the including function
> >>> has been called. But yes, it will be available to the including function.
> >>>
> >> Actually, which would mean that the including function had been called
> >> if it was attempting to use any of the vars/functions in the included
> >> file :-)
> >
> > You need to work on your use of verb tenses :)
> >
> > Cheers,
> > Rob.
>
> What? I didn't know you flamed people whose native language wasn't
> English! How can we get a break on this list?
>
> I speak Texan (sorta), and apologize for my poor English. :-(
I wasn't flaming, I was providing insight into why your wording was
confusing. If I had been flaming I would have used sarcasm or derogatory
phrasing to demean your words.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Hi all,
I'm using PHP 5.2.9 on a Windows dedicated server. Could you kindly
confirm me that I have to update to PHP 5.2.9-1
(http://www.php.net/archive/2009.php#id2009-03-10-1) only if I have
"curl" extension enabled (extension=php_curl.dll in php.ini) ?
If I run a phpinfo() on my webserver, no "curl" section is shown (no
extension=php_curl.dll in php.ini). So, is my configuration (Windows
2003 Server - PHP 5.2.9) safe?
Thank you.
--- End Message ---
--- Begin Message ---
... nobody a clue? ...
--------------------------------------------------------
Hi everybody,
I am a Certified Zend Engineer with almost 10 years of PHP development
experience but for some reason I've never asked question to this ML.
As subject says, I would like to know if there a generic extension/3rd
parts/solution to save the state of a built-in PHP object.
I perfectly know that __sleep and __wakeup or ... implements
Serializable { ... } could allow me to store and retrieve serialized
data but what I did not expect is that APC just behaves as serialize
and "nothing more" than that.
Here there is a quick explanation:
$xsltp = new XSLTProcessor;
$xsltp->importStylesheet(
DomDocument::load('random.xsl')
);
// no way to store the variable here with its live state
// without re-importing stylesheet on __wakeup or unserialize
echo $xsltp->transformToXML(
DomDocument::load('random.xml')
);
I agree that this built-in stuff could be consider a weird case but I
cannot believe that with all these new classes there is no solution to
truly hibernate instances state.
As summary, I wonder if any of you knows a solution or, if any, when (and if)
are you planning to add this feature.
Best Regards
_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/products/events.aspx
--- End Message ---
--- Begin Message ---
On Wed, Mar 11, 2009 at 7:51 PM, Patrick Moloney <[email protected]> wrote:
> OK, I think I've got the problem. I had to go back further than where the
> problem appeared to be. The 1st error was the comment code on the div line
> before the menu is Included. It had the "--" in the comment.
> Oddly, it interacts with the same error in the comment in the mainmenu file.
> I saw some suggestion that these work in pairs but fail in odd numbers. So,
> I have many pages that work like this.
> Adding another bad comment to the mainmenu, causes it to fail (3 bad lines).
> Or, without a third line, fixing the only bad line in the mainmenu also
> fails! Now, correcting the bad line in the web page fixes that -- (whoops) -
> but causes all the other similar web site pages to start failing.
> I'll have to fix them all, but at least I know the problem.
> No wonder nobody comments code!
>
>
> mainmenu.php
>
> <!-- Comment on the First Line -->
> <!-- Comment on the -- Second Line -->
> Functional Menu code
> ...
>
>
> webpage.php
> ...
> <Body>
> <div id="menu"> <!-- Include the -- menu here -->
> <?php include 'mainmenu.php'; ?>
> </div>
> ...
>
I do use PHP comments (probably not as much as I should), but I don't
usually use HTML comments. This is partly (largely?) because HTML
comments get passed on to the client which wastes (albeit usually a
small amount of) extra space and bandwidth for each request, and they
give out implementation details to people who least need to know them.
I can sort of see adding the HTML comments when designing a full page
template so it is easier to determine where dynamic content needs to
be inserted when you start slicing the template apart, but even then I
usually remove those comments later in the design process before I put
the code out for production. Then again, I haven't included files for
anything other than function/class libraries in years either.
Andrew
--- End Message ---
--- Begin Message ---
At 3:38 PM -0400 3/11/09, Robert Cummings wrote:
Just because I'm a nice guy... :)
Yeah, me too -- here are three routines I use for cutting the right,
left and middle portions of strings. These were keyword routines I
used in FutureBasic -- they seemed to make sense to me so I carried
them into php.
<?php
// ====== returns the right-most number of characters from a string
// $string = "123456789"
// right($string, 3) returns "123"
function right($string, $length)
{
$str = substr($string, -$length, $length);
return $str;
}
// ====== returns the left-most number of characters from a string
// $string = "123456789"
// left($string, 3) returns "789"
function left($string, $length)
{
$str = substr($string, 0, $length);
return $str;
}
// ====== returns the middle number of characters from a string
starting from the left
// $string = "123456789"
// mid($string, 3, 4) returns "4567"
function mid($string, $left_start, $length)
{
$str = substr($string, $left_start, $length);
return $str;
}
?>
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---