php-general Digest 8 Jan 2010 07:25:00 -0000 Issue 6527

2010-01-07 Thread php-general-digest-help

php-general Digest 8 Jan 2010 07:25:00 - Issue 6527

Topics (messages 300889 through 300897):

Re: First time PHP user question
300889 by: Jim Lucas

cannot access SimpleXML object property
300890 by: Mari Masuda
300891 by: Jonathan Tapicer
300892 by: Mari Masuda

Re: PHP programming strategy; lots of little include files, or a few big ones?
300893 by: clancy_1.cybec.com.au
300894 by: clancy_1.cybec.com.au
300896 by: Robert Cummings
300897 by: clancy_1.cybec.com.au

Re: Site Moved From PHP4 to PHP5 Server - header, location no longer working
300895 by: Vernon Webb

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

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


--
---BeginMessage---
Ashley Sheridan wrote:
 On Thu, 2010-01-07 at 08:32 -0500, Rick Dwyer wrote:
 
 Thanks Ashley  Nathan.

 As it turns out, there is more than one tmp folder... and I was  
 looking in the wrong one.  When I SSH'd in the correct one, I created  
 the missing file and it began to work properly.
 Thanks for chiming in.

 --Rick


 On Jan 7, 2010, at 7:58 AM, Ashley Sheridan wrote:

 On Thu, 2010-01-07 at 09:19 +, Nathan Rixham wrote:
 Rick Dwyer wrote:
 Hello List.
 I have been playing around with PHP, running a few tutorials and  
 I came
 across an error message I could not resolve.

 The tutorial is Generating One Time URL's by Oreilly:
 http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html

 Basically the PHP code is supposed to read from a text file and  
 write to
 a text file and serve a text file all located in the tmp  
 directory of
 the server.

 However, I receive the error that the referenced files in the PHP  
 code
 could not be found:
 Warning: readfile(/tmp/secret_file.txt) [function.readfile]:  
 failed to
 open stream: No such file or directory
 in/home/mysite/myfolder/get_file.php on line 67

 Line 66 and 67 look like this:

 $secretfile = /tmp/secret_file.txt;
 readfile($secretfile);


 However, in the tmp folder, I have created a simple text file  
 called
 secret_file.txt so I know it exists and it has the permissions  
 set to
 644, so it should be readable.

 Can someone point out to me what I am doing wrong?  Thanks,

 try permissions of 777 and see if the error disappears; odds are v  
 high
 that the httpd user php is running under doesn't have group or owner
 permissions for /tmp  that secret file.

 regards


 That shouldn't fix it. 644 permissions allow the owner, group users  
 and anybody else to read file. Have you tried is_file(/tmp/ 
 secret_file.txt); to see if it actually exists? Also, don't forget  
 that Linux is case sensitive when it comes to filenames, so  
 secret_file.txt is completely different from Secret_File.txt, and in- 
 fact you can validly have both in the same directory.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



   --Rick



 
 There isn't more than one /tmp folder, that is impossible. There was
 probably more than one tmp folder, and you weren't looking in the right
 one.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 

Actually, Ash, you can have more then one /tmp folder.  Depends on what app is
looking at it.

If you have PHP running with Apache and Apache is jailed, the the /tmp folder
would be from the perspective to the jail the the actual OS.

So, if apache was jailed to /var/www/ you could then have a /tmp/ and a
/var/www/tmp/

Apache would never see the /tmp/ only the /var/www/tmp/
---End Message---
---BeginMessage---
Hi,

I am working with an XML document and have a SimpleXML object whose var_dump 
looks like this:

---
object(SimpleXMLElement)#2 (10) {
  [@attributes]=
  array(1) {
[id]=
string(7) 3854857
  }
  [type]=
  string(7) Article
  [createDate]=
  string(25) 2006-09-06T16:42:20-07:00
  [editDate]=
  string(25) 2007-07-16T09:15:53-07:00
  [creator]=
  string(19) Michael Gottfredson
  [status]=
  string(5) ready
  [field]=
  ...snip a bunch of stuff...
}
---

Assuming the above object is referenced by $current_object, I can access the 
values of most stuff with $current_object-creator or whatever.  However, I 
cannot figure out how to access the value of id.  I tried the following, none 
of which worked for me:

1.  $current_object-@attributes-id (gives Parse error: syntax error, 
unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in 
/Applications/apache/htdocs/test.php on line 33)

2.  $current_object-'@attributes'-id (gives Parse error: syntax error, 
unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' 
or '$' in/Applications/apache/htdocs/test.php on line 33)

3.  $current_object-{...@attributes}-id (no error but is null)

4.  $current_object-{'@attributes'}-id (no error 

[PHP] Newbie needs help

2010-01-07 Thread John Taylor-Johnston


$content = ... a bunch of text with some !--protected--protected 
information!--/protected-- with some more text with some more 
!--protected--tabletrtdmore protected 
text/td/tr/table!--/protected-- and even !--protected--bsome 
protected contentb!--/protected--;


I want to replace any content between these tags:
!--protected--!--/protected--
with say

$replacewith = strongprotected content/strong;


$content =  a bunch of text with some strongprotected 
content/strong with some more text with some more strongprotected 
content/strong and even strongprotected content/strong;


It's a little more involved than str_replace which is about the limit of 
my knowledge.


Any takers - to take pity on me? I'm trying to figure out some funky 
WordPress stuff as it is.


John

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



Re: [PHP] Unable to get output from exec ssh remote-server 'ping -c4 ip'

2010-01-07 Thread hack988 hack988
see this
http://www.phpclasses.org/browse/package/4282.html

2009/12/28 robert mena robert.m...@gmail.com:
 Hi,

 I need to develop an interface that will, for example, ping IPs from a
 remote server. So the php script will be hosted in a server with ssh access
 (key) to the remote server.

 I can make it work from the console but when I try

 $cmd = ssh remote-server 'ping -c 4 ip'
 exec($cmd, $ouput);

 the output is empty.

 the same command (with the remote-server and IP changed to the real ones)
 works fine from command line.

 I've added the key/config in the webserver's user .ssh directory so I am
 assuming that that there is something wrong with my setup.

 any ideas?


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



Re: [PHP] Newbie needs help

2010-01-07 Thread viraj
try http://www.php.net/manual/en/function.preg-replace-callback.php.
you need to read a bit on 'regular expressions'

http://www.gskinner.com/RegExr/ will be handy in crafting a suitable
regex to capture your 'tags'

~viraj

On Thu, Jan 7, 2010 at 2:16 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

 $content = ... a bunch of text with some !--protected--protected
 information!--/protected-- with some more text with some more
 !--protected--tabletrtdmore protected
 text/td/tr/table!--/protected-- and even !--protected--bsome
 protected contentb!--/protected--;

 I want to replace any content between these tags:
 !--protected--!--/protected--
 with say

 $replacewith = strongprotected content/strong;


 $content =  a bunch of text with some strongprotected content/strong
 with some more text with some more strongprotected content/strong and
 even strongprotected content/strong;

 It's a little more involved than str_replace which is about the limit of my
 knowledge.

 Any takers - to take pity on me? I'm trying to figure out some funky
 WordPress stuff as it is.

 John

 --
 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



Re: [PHP] Newbie needs help

2010-01-07 Thread John Taylor-Johnston

Great. Ok. Thanks. [I'm a top quoter)]. I'll look at it.

This was my dirty way of hacking it:

if (($current_user-id == 0)  ($user_ID == 0))
{
$content = str_replace('!--protected--', 'bProtected !--', $content);
$content = str_replace('!--/protected--', '-- Content/b a 
href=/wp-login.php[Log in here/a]', $content);

}

Cheap  Dirty and need refinement :p

viraj wrote:

try http://www.php.net/manual/en/function.preg-replace-callback.php.
you need to read a bit on 'regular expressions'

http://www.gskinner.com/RegExr/ will be handy in crafting a suitable
regex to capture your 'tags'

~viraj

On Thu, Jan 7, 2010 at 2:16 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca  wrote:
   

$content = ... a bunch of text with some!--protected--protected
information!--/protected--  with some more text with some more
!--protected--tabletrtdmore protected
text/td/tr/table!--/protected--  and even!--protected--bsome
protected contentb!--/protected--;

I want to replace any content between these tags:
!--protected--!--/protected--
with say

$replacewith = strongprotected content/strong;


$content =  a bunch of text with somestrongprotected content/strong
with some more text with some morestrongprotected content/strong  and
evenstrongprotected content/strong;

It's a little more involved than str_replace which is about the limit of my
knowledge.

Any takers - to take pity on me? I'm trying to figure out some funky
WordPress stuff as it is.

John

--
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



[PHP] Call to undefined method on class property!?

2010-01-07 Thread Allen McCabe
I have a singleton database object in a global file at the top of my
document. In most other locations I am able to access it just fine, however
in my footer I want to loop through a properties list for links (I am saving
links to a database, each with its own properties).

Here is the code snippet that is giving me trouble:

footerlinks.inc.php:

?php
$result = $db-query('SELECT * FROM `links` WHERE `category` =
\'footer_navigation\';');
$total = $db-affected_rows;

if ($total  0)
{
$Link = new Link();
$count = $db-affected_rows($result);
$i = 0;
while ($row = $db-fetch_array($result))
{
$properties = $Link-setLinkProperties($row);

$link[$i] = 'a ';
foreach ($properties as $prop)
{
$link[$i] .= $prop;
}
$link[$i] .= '';
$row['text'];
$link[$i] .= '/a';

$i++;
}

$j = 0;
while ($j  $link)
{
echo $link[$j];
if ($j  $count)
{
echo ' | ';
}

$j++;
}

}

?

The $Link-$Link-setLinkProperties() method is defined in

Link.class.php:

?php

class Link {

public function setLinkProperties($rows)
{
if (!empty($row['href']))
{
$properties['href'] = 'href=' . $row['href'] . ' ';
}

if (!empty($row['class']))
{
$properties['class'] = 'class=' . $row['class'] . ' ';
}

if (!empty($row['style']))
{
$properties['style'] = 'style=' . $row['style'] . ' ';
}

if (!empty($row['title']))
{
$properties['title'] = 'title=' . $row['title'] . ' ';
}

if (!empty($row['name']))
{
$properties['name'] = 'name=' . $row['name'] . ' ';
}

if (!empty($row['target']))
{
$properties['target'] = 'target=' . $row['target'] . ' ';
}

if (!empty($row['rel']))
{
$properties['rel'] = 'rel=' . $row['rel'] . ' ';
}

if (!empty($row['onclick']))
{
$properties['onclick'] = 'onclick=' . $row['onclick'] . ' ';
}

if (!empty($row['ondblclick']))
{
$properties['ondblclick'] = 'ondblclick=' . $row['ondblclick']
. ' ';
}

if (!empty($row['onmouseover']))
{
$properties['onmouseover'] = 'onmouseover=' .
$row['onmouseover'] . ' ';
}

if (!empty($row['onmouseout']))
{
$properties['onmouseout'] = 'onmouseout=' . $row['onmouseout']
. ' ';
}

return $properties;

} // END OF METHOD setLinkProperties
} // END OF CLASS

?

Also for reference, the method query() in my database class sets a value for
$affected_rows:

Database.class.php:

?php

class Database {

private $server   = ''; //database server
private $user = ''; //database login name
private $pass = ''; //database login password
private $database = ''; //database name
private $pre  = ''; //table prefix

###
//internal info
private $error = '';
private $errno = 0;

//number of rows affected by SQL query
public $affected_rows = 0;

...

?

This is the error I am receiving:

*Fatal error*: Call to undefined method Database::affected_rows() in *
/home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*

Please help PHP gurus!!


Re: [PHP] Call to undefined method on class property!?

2010-01-07 Thread Darren Karstens
Do you have a method in your Database class called affected_rows() ?
From the code you have shown you only have a member variable called
affected_rows and so your call $db-fetch_array($result) is falling
over.

On Thu, Jan 7, 2010 at 8:47 AM, Allen McCabe allenmcc...@gmail.com wrote:
 I have a singleton database object in a global file at the top of my
 document. In most other locations I am able to access it just fine, however
 in my footer I want to loop through a properties list for links (I am saving
 links to a database, each with its own properties).

 Here is the code snippet that is giving me trouble:

 footerlinks.inc.php:

 ?php
        $result = $db-query('SELECT * FROM `links` WHERE `category` =
 \'footer_navigation\';');
        $total = $db-affected_rows;

        if ($total  0)
        {
            $Link = new Link();
            $count = $db-affected_rows($result);
            $i = 0;
            while ($row = $db-fetch_array($result))
            {
                $properties = $Link-setLinkProperties($row);

                $link[$i] = 'a ';
                foreach ($properties as $prop)
                {
                    $link[$i] .= $prop;
                }
                $link[$i] .= '';
                $row['text'];
                $link[$i] .= '/a';

                $i++;
            }

            $j = 0;
            while ($j  $link)
            {
                echo $link[$j];
                if ($j  $count)
                {
                    echo ' | ';
                }

                $j++;
            }

        }

    ?

 The $Link-$Link-setLinkProperties() method is defined in

 Link.class.php:

 ?php

 class Link {

    public function setLinkProperties($rows)
    {
        if (!empty($row['href']))
        {
            $properties['href'] = 'href=' . $row['href'] . ' ';
        }

        if (!empty($row['class']))
        {
            $properties['class'] = 'class=' . $row['class'] . ' ';
        }

        if (!empty($row['style']))
        {
            $properties['style'] = 'style=' . $row['style'] . ' ';
        }

        if (!empty($row['title']))
        {
            $properties['title'] = 'title=' . $row['title'] . ' ';
        }

        if (!empty($row['name']))
        {
            $properties['name'] = 'name=' . $row['name'] . ' ';
        }

        if (!empty($row['target']))
        {
            $properties['target'] = 'target=' . $row['target'] . ' ';
        }

        if (!empty($row['rel']))
        {
            $properties['rel'] = 'rel=' . $row['rel'] . ' ';
        }

        if (!empty($row['onclick']))
        {
            $properties['onclick'] = 'onclick=' . $row['onclick'] . ' ';
        }

        if (!empty($row['ondblclick']))
        {
            $properties['ondblclick'] = 'ondblclick=' . $row['ondblclick']
 . ' ';
        }

        if (!empty($row['onmouseover']))
        {
            $properties['onmouseover'] = 'onmouseover=' .
 $row['onmouseover'] . ' ';
        }

        if (!empty($row['onmouseout']))
        {
            $properties['onmouseout'] = 'onmouseout=' . $row['onmouseout']
 . ' ';
        }

        return $properties;

    } // END OF METHOD setLinkProperties
 } // END OF CLASS

 ?

 Also for reference, the method query() in my database class sets a value for
 $affected_rows:

 Database.class.php:

 ?php

 class Database {

    private $server   = ''; //database server
    private $user     = ''; //database login name
    private $pass     = ''; //database login password
    private $database = ''; //database name
    private $pre      = ''; //table prefix

    ###
    //internal info
    private $error = '';
    private $errno = 0;

    //number of rows affected by SQL query
    public $affected_rows = 0;

 ...

 ?

 This is the error I am receiving:

 *Fatal error*: Call to undefined method Database::affected_rows() in *
 /home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*

 Please help PHP gurus!!


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



[PHP] Re: Resin/Quercus

2010-01-07 Thread Nathan Rixham
Mattias Thorslund wrote:
 Hi,
 
 I wonder if anyone has experience with running PHP on the Resin server.
 Opinions, good, bad? Gotchas? Similar projects?
 
 http://www.caucho.com/projects/resin/
 
 Thanks,
 
 Mattias

Resin is excellent - especially if you need to integrate in with java
apps closer to the iron, also found it ran most php 5 OO apps a bit
faster. Also runs well on glassfish if your so inclined.

Regards,

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



[PHP] Re: First time PHP user question

2010-01-07 Thread Nathan Rixham
Rick Dwyer wrote:
 Hello List.
 I have been playing around with PHP, running a few tutorials and I came
 across an error message I could not resolve.
 
 The tutorial is Generating One Time URL's by Oreilly:
 http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html
 
 Basically the PHP code is supposed to read from a text file and write to
 a text file and serve a text file all located in the tmp directory of
 the server.
 
 However, I receive the error that the referenced files in the PHP code
 could not be found:
 Warning: readfile(/tmp/secret_file.txt) [function.readfile]: failed to
 open stream: No such file or directory
 in/home/mysite/myfolder/get_file.php on line 67
 
 Line 66 and 67 look like this:
 
 $secretfile = /tmp/secret_file.txt;
 readfile($secretfile);
 
 
 However, in the tmp folder, I have created a simple text file called
 secret_file.txt so I know it exists and it has the permissions set to
 644, so it should be readable.
 
 Can someone point out to me what I am doing wrong?  Thanks,
 

try permissions of 777 and see if the error disappears; odds are v high
that the httpd user php is running under doesn't have group or owner
permissions for /tmp  that secret file.

regards


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



Re: [PHP] Call to undefined method on class property!?

2010-01-07 Thread Thijs Lensselink

Allen McCabe wrote:

I have a singleton database object in a global file at the top of my
document. In most other locations I am able to access it just fine, however
in my footer I want to loop through a properties list for links (I am saving
links to a database, each with its own properties).

Here is the code snippet that is giving me trouble:

footerlinks.inc.php:

?php
$result = $db-query('SELECT * FROM `links` WHERE `category` =
\'footer_navigation\';');
$total = $db-affected_rows;


Here you use affected_rows as a class property to assign a value to a 
variable.




if ($total  0)
{
$Link = new Link();
$count = $db-affected_rows($result);


Here you call affected_rows as a class method. And from looking at your 
Database class. affected_rows is a property not a method. So that 
explains the undefined method error.




$i = 0;
while ($row = $db-fetch_array($result))
{
$properties = $Link-setLinkProperties($row);

$link[$i] = 'a ';
foreach ($properties as $prop)
{
$link[$i] .= $prop;
}
$link[$i] .= '';
$row['text'];
$link[$i] .= '/a';

$i++;
}

$j = 0;
while ($j  $link)
{
echo $link[$j];
if ($j  $count)
{
echo ' | ';
}

$j++;
}

}

?

The $Link-$Link-setLinkProperties() method is defined in

Link.class.php:

?php

class Link {

public function setLinkProperties($rows)
{
if (!empty($row['href']))
{
$properties['href'] = 'href=' . $row['href'] . ' ';
}

if (!empty($row['class']))
{
$properties['class'] = 'class=' . $row['class'] . ' ';
}

if (!empty($row['style']))
{
$properties['style'] = 'style=' . $row['style'] . ' ';
}

if (!empty($row['title']))
{
$properties['title'] = 'title=' . $row['title'] . ' ';
}

if (!empty($row['name']))
{
$properties['name'] = 'name=' . $row['name'] . ' ';
}

if (!empty($row['target']))
{
$properties['target'] = 'target=' . $row['target'] . ' ';
}

if (!empty($row['rel']))
{
$properties['rel'] = 'rel=' . $row['rel'] . ' ';
}

if (!empty($row['onclick']))
{
$properties['onclick'] = 'onclick=' . $row['onclick'] . ' ';
}

if (!empty($row['ondblclick']))
{
$properties['ondblclick'] = 'ondblclick=' . $row['ondblclick']
. ' ';
}

if (!empty($row['onmouseover']))
{
$properties['onmouseover'] = 'onmouseover=' .
$row['onmouseover'] . ' ';
}

if (!empty($row['onmouseout']))
{
$properties['onmouseout'] = 'onmouseout=' . $row['onmouseout']
. ' ';
}

return $properties;

} // END OF METHOD setLinkProperties
} // END OF CLASS

?

Also for reference, the method query() in my database class sets a value for
$affected_rows:

Database.class.php:

?php

class Database {

private $server   = ''; //database server
private $user = ''; //database login name
private $pass = ''; //database login password
private $database = ''; //database name
private $pre  = ''; //table prefix

###
//internal info
private $error = '';
private $errno = 0;

//number of rows affected by SQL query
public $affected_rows = 0;

...

?

This is the error I am receiving:

*Fatal error*: Call to undefined method Database::affected_rows() in *
/home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*

Please help PHP gurus!!




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



Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-07 Thread Daniel Egeberg
On Thu, Jan 7, 2010 at 04:11, Daevid Vincent dae...@daevid.com wrote:
 I think it's a case by case basis. Generally File I/O is expensive, but
 then again, as you say, having everything in a couple files is also
 sub-optimal for organizing and keeping things modular.

That is easily sorted out using automated build tools like Phing, Ant
or GNU Make.

Either way, I wouldn't worry about the extra I/O unless you've got *a
lot* of traffic.

-- 
Daniel Egeberg

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



Re: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no longer working

2010-01-07 Thread Ashley Sheridan
On Thu, 2010-01-07 at 16:50 +1030, James McLean wrote:

 On Thu, Jan 7, 2010 at 1:35 PM, Vernon Webb ver...@comp-wiz.com wrote:
  I move a number of sites from one server to another and one the one server 
  we had php4 and now we have php5 and since then my server seems to hang 
  every time there is a header, location redirect. Anyone have any ideas on 
  how to resolve this? Is there something I can easily change in the php.ini 
  file that will resolve this issue?
 
 Off the top of my head it sounds like something is being output before
 the header, which causes an error. If you also have error display
 turned off, you will likely just see a white screen with no useful
 information.
 
 Make sure none of your includes have trailing whitespace or are trying
 to print out information before the header itself.
 
 Best bet is to turn on errors and log them, then you will see where
 the output started if infact that is your issue.
 
 Cheers
 


Don't turn on errors if this machine is public, as it could potentially
give out more information to people than you want. First, look at the
error logs for PHP, which record all the errors you've had with the
site, whether you have them displayed or not.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: First time PHP user question

2010-01-07 Thread Ashley Sheridan
On Thu, 2010-01-07 at 09:19 +, Nathan Rixham wrote:

 Rick Dwyer wrote:
  Hello List.
  I have been playing around with PHP, running a few tutorials and I came
  across an error message I could not resolve.
  
  The tutorial is Generating One Time URL's by Oreilly:
  http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html
  
  Basically the PHP code is supposed to read from a text file and write to
  a text file and serve a text file all located in the tmp directory of
  the server.
  
  However, I receive the error that the referenced files in the PHP code
  could not be found:
  Warning: readfile(/tmp/secret_file.txt) [function.readfile]: failed to
  open stream: No such file or directory
  in/home/mysite/myfolder/get_file.php on line 67
  
  Line 66 and 67 look like this:
  
  $secretfile = /tmp/secret_file.txt;
  readfile($secretfile);
  
  
  However, in the tmp folder, I have created a simple text file called
  secret_file.txt so I know it exists and it has the permissions set to
  644, so it should be readable.
  
  Can someone point out to me what I am doing wrong?  Thanks,
  
 
 try permissions of 777 and see if the error disappears; odds are v high
 that the httpd user php is running under doesn't have group or owner
 permissions for /tmp  that secret file.
 
 regards
 
 


That shouldn't fix it. 644 permissions allow the owner, group users and
anybody else to read file. Have you tried
is_file(/tmp/secret_file.txt); to see if it actually exists? Also,
don't forget that Linux is case sensitive when it comes to filenames, so
secret_file.txt is completely different from Secret_File.txt, and
in-fact you can validly have both in the same directory.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: First time PHP user question

2010-01-07 Thread Rick Dwyer

Thanks Ashley  Nathan.

As it turns out, there is more than one tmp folder... and I was  
looking in the wrong one.  When I SSH'd in the correct one, I created  
the missing file and it began to work properly.

Thanks for chiming in.

--Rick


On Jan 7, 2010, at 7:58 AM, Ashley Sheridan wrote:


On Thu, 2010-01-07 at 09:19 +, Nathan Rixham wrote:


Rick Dwyer wrote:
 Hello List.
 I have been playing around with PHP, running a few tutorials and  
I came

 across an error message I could not resolve.

 The tutorial is Generating One Time URL's by Oreilly:
 http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html

 Basically the PHP code is supposed to read from a text file and  
write to
 a text file and serve a text file all located in the tmp  
directory of

 the server.

 However, I receive the error that the referenced files in the PHP  
code

 could not be found:
 Warning: readfile(/tmp/secret_file.txt) [function.readfile]:  
failed to

 open stream: No such file or directory
 in/home/mysite/myfolder/get_file.php on line 67

 Line 66 and 67 look like this:

 $secretfile = /tmp/secret_file.txt;
 readfile($secretfile);


 However, in the tmp folder, I have created a simple text file  
called
 secret_file.txt so I know it exists and it has the permissions  
set to

 644, so it should be readable.

 Can someone point out to me what I am doing wrong?  Thanks,


try permissions of 777 and see if the error disappears; odds are v  
high

that the httpd user php is running under doesn't have group or owner
permissions for /tmp  that secret file.

regards




That shouldn't fix it. 644 permissions allow the owner, group users  
and anybody else to read file. Have you tried is_file(/tmp/ 
secret_file.txt); to see if it actually exists? Also, don't forget  
that Linux is case sensitive when it comes to filenames, so  
secret_file.txt is completely different from Secret_File.txt, and in- 
fact you can validly have both in the same directory.


Thanks,
Ash
http://www.ashleysheridan.co.uk





 --Rick



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



Re: [PHP] Re: First time PHP user question

2010-01-07 Thread Ashley Sheridan
On Thu, 2010-01-07 at 08:32 -0500, Rick Dwyer wrote:

 Thanks Ashley  Nathan.
 
 As it turns out, there is more than one tmp folder... and I was  
 looking in the wrong one.  When I SSH'd in the correct one, I created  
 the missing file and it began to work properly.
 Thanks for chiming in.
 
 --Rick
 
 
 On Jan 7, 2010, at 7:58 AM, Ashley Sheridan wrote:
 
  On Thu, 2010-01-07 at 09:19 +, Nathan Rixham wrote:
 
  Rick Dwyer wrote:
   Hello List.
   I have been playing around with PHP, running a few tutorials and  
  I came
   across an error message I could not resolve.
  
   The tutorial is Generating One Time URL's by Oreilly:
   http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html
  
   Basically the PHP code is supposed to read from a text file and  
  write to
   a text file and serve a text file all located in the tmp  
  directory of
   the server.
  
   However, I receive the error that the referenced files in the PHP  
  code
   could not be found:
   Warning: readfile(/tmp/secret_file.txt) [function.readfile]:  
  failed to
   open stream: No such file or directory
   in/home/mysite/myfolder/get_file.php on line 67
  
   Line 66 and 67 look like this:
  
   $secretfile = /tmp/secret_file.txt;
   readfile($secretfile);
  
  
   However, in the tmp folder, I have created a simple text file  
  called
   secret_file.txt so I know it exists and it has the permissions  
  set to
   644, so it should be readable.
  
   Can someone point out to me what I am doing wrong?  Thanks,
  
 
  try permissions of 777 and see if the error disappears; odds are v  
  high
  that the httpd user php is running under doesn't have group or owner
  permissions for /tmp  that secret file.
 
  regards
 
 
 
  That shouldn't fix it. 644 permissions allow the owner, group users  
  and anybody else to read file. Have you tried is_file(/tmp/ 
  secret_file.txt); to see if it actually exists? Also, don't forget  
  that Linux is case sensitive when it comes to filenames, so  
  secret_file.txt is completely different from Secret_File.txt, and in- 
  fact you can validly have both in the same directory.
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 
 
   --Rick
 
 
 

There isn't more than one /tmp folder, that is impossible. There was
probably more than one tmp folder, and you weren't looking in the right
one.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no longer working

2010-01-07 Thread Vernon Webb
That's the odd thing, there is nothing being indicated in the error logs the 
server just hangs and I have to restart apache in order to get the site back 
up. First I thought it might be the server so I move over to a different 
server, but I still have the same issue. What I feel is really odd is the fact 
that it worked in a previous version of php, so waht's changed?
 
~V



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: Thu 1/7/2010 7:52 AM
To: James McLean
Cc: Vernon Webb; php-general@lists.php.net
Subject: Re: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no 
longer working


On Thu, 2010-01-07 at 16:50 +1030, James McLean wrote: 

On Thu, Jan 7, 2010 at 1:35 PM, Vernon Webb ver...@comp-wiz.com wrote:
 I move a number of sites from one server to another and one the one 
server we had php4 and now we have php5 and since then my server seems to hang 
every time there is a header, location redirect. Anyone have any ideas on how 
to resolve this? Is there something I can easily change in the php.ini file 
that will resolve this issue?

Off the top of my head it sounds like something is being output before
the header, which causes an error. If you also have error display
turned off, you will likely just see a white screen with no useful
information.

Make sure none of your includes have trailing whitespace or are trying
to print out information before the header itself.

Best bet is to turn on errors and log them, then you will see where
the output started if infact that is your issue.

Cheers



Don't turn on errors if this machine is public, as it could potentially give 
out more information to people than you want. First, look at the error logs for 
PHP, which record all the errors you've had with the site, whether you have 
them displayed or not.


Thanks,
Ash
http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/ 




-- 
This message has been scanned for viruses and 
dangerous content by comp-wiz.com http://comp-wiz.com/ , and is 
believed to be clean. 


RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no longer working

2010-01-07 Thread Ashley Sheridan
On Thu, 2010-01-07 at 08:40 -0500, Vernon Webb wrote:

 That's the odd thing, there is nothing being indicated in the error logs the 
 server just hangs and I have to restart apache in order to get the site back 
 up. First I thought it might be the server so I move over to a different 
 server, but I still have the same issue. What I feel is really odd is the 
 fact that it worked in a previous version of php, so waht's changed?
  
 ~V
 
 
 
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
 Sent: Thu 1/7/2010 7:52 AM
 To: James McLean
 Cc: Vernon Webb; php-general@lists.php.net
 Subject: Re: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no 
 longer working
 
 
 On Thu, 2010-01-07 at 16:50 +1030, James McLean wrote: 
 
   On Thu, Jan 7, 2010 at 1:35 PM, Vernon Webb ver...@comp-wiz.com wrote:
I move a number of sites from one server to another and one the one 
 server we had php4 and now we have php5 and since then my server seems to 
 hang every time there is a header, location redirect. Anyone have any ideas 
 on how to resolve this? Is there something I can easily change in the php.ini 
 file that will resolve this issue?
   
   Off the top of my head it sounds like something is being output before
   the header, which causes an error. If you also have error display
   turned off, you will likely just see a white screen with no useful
   information.
   
   Make sure none of your includes have trailing whitespace or are trying
   to print out information before the header itself.
   
   Best bet is to turn on errors and log them, then you will see where
   the output started if infact that is your issue.
   
   Cheers
   
 
 
 Don't turn on errors if this machine is public, as it could potentially give 
 out more information to people than you want. First, look at the error logs 
 for PHP, which record all the errors you've had with the site, whether you 
 have them displayed or not.
 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/ 
 
 
   
 


Have you checked both the PHP and Apache error logs? Things like invalid
commands in an .htaccess file can cause server crashes.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no longer working

2010-01-07 Thread Vernon Webb
Didn't know there were php logs, I thought they would be included in the Apache 
logs, where do I find the php logs?
 
~V



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: Thu 1/7/2010 8:42 AM
To: Vernon Webb
Cc: php-general@lists.php.net
Subject: RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no 
longer working


On Thu, 2010-01-07 at 08:40 -0500, Vernon Webb wrote: 

That's the odd thing, there is nothing being indicated in the error 
logs the server just hangs and I have to restart apache in order to get the 
site back up. First I thought it might be the server so I move over to a 
different server, but I still have the same issue. What I feel is really odd is 
the fact that it worked in a previous version of php, so waht's changed?
 
~V



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: Thu 1/7/2010 7:52 AM
To: James McLean
Cc: Vernon Webb; php-general@lists.php.net
Subject: Re: [PHP] Site Moved From PHP4 to PHP5 Server - header, 
location no longer working


On Thu, 2010-01-07 at 16:50 +1030, James McLean wrote: 

On Thu, Jan 7, 2010 at 1:35 PM, Vernon Webb 
ver...@comp-wiz.com wrote:
 I move a number of sites from one server to another and one 
the one server we had php4 and now we have php5 and since then my server seems 
to hang every time there is a header, location redirect. Anyone have any ideas 
on how to resolve this? Is there something I can easily change in the php.ini 
file that will resolve this issue?

Off the top of my head it sounds like something is being output 
before
the header, which causes an error. If you also have error 
display
turned off, you will likely just see a white screen with no 
useful
information.

Make sure none of your includes have trailing whitespace or are 
trying
to print out information before the header itself.

Best bet is to turn on errors and log them, then you will see 
where
the output started if infact that is your issue.

Cheers



Don't turn on errors if this machine is public, as it could potentially 
give out more information to people than you want. First, look at the error 
logs for PHP, which record all the errors you've had with the site, whether you 
have them displayed or not.


Thanks,
Ash
http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/  
http://www.ashleysheridan.co.uk/ 






Have you checked both the PHP and Apache error logs? Things like invalid 
commands in an .htaccess file can cause server crashes.


Thanks,
Ash
http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/ 




-- 
This message has been scanned for viruses and 
dangerous content by comp-wiz.com http://comp-wiz.com/ , and is 
believed to be clean. 


RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no longer working

2010-01-07 Thread Ashley Sheridan
On Thu, 2010-01-07 at 08:57 -0500, Vernon Webb wrote:

 Didn't know there were php logs, I thought they would be included in the 
 Apache logs, where do I find the php logs?
  
 ~V
 
 
 
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
 Sent: Thu 1/7/2010 8:42 AM
 To: Vernon Webb
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no 
 longer working
 
 
 On Thu, 2010-01-07 at 08:40 -0500, Vernon Webb wrote: 
 
   That's the odd thing, there is nothing being indicated in the error 
 logs the server just hangs and I have to restart apache in order to get the 
 site back up. First I thought it might be the server so I move over to a 
 different server, but I still have the same issue. What I feel is really odd 
 is the fact that it worked in a previous version of php, so waht's changed?

   ~V
   
   
   
   From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
   Sent: Thu 1/7/2010 7:52 AM
   To: James McLean
   Cc: Vernon Webb; php-general@lists.php.net
   Subject: Re: [PHP] Site Moved From PHP4 to PHP5 Server - header, 
 location no longer working
   
   
   On Thu, 2010-01-07 at 16:50 +1030, James McLean wrote: 
   
   On Thu, Jan 7, 2010 at 1:35 PM, Vernon Webb 
 ver...@comp-wiz.com wrote:
I move a number of sites from one server to another and one 
 the one server we had php4 and now we have php5 and since then my server 
 seems to hang every time there is a header, location redirect. Anyone have 
 any ideas on how to resolve this? Is there something I can easily change in 
 the php.ini file that will resolve this issue?
   
   Off the top of my head it sounds like something is being output 
 before
   the header, which causes an error. If you also have error 
 display
   turned off, you will likely just see a white screen with no 
 useful
   information.
   
   Make sure none of your includes have trailing whitespace or are 
 trying
   to print out information before the header itself.
   
   Best bet is to turn on errors and log them, then you will see 
 where
   the output started if infact that is your issue.
   
   Cheers
   
   
   
   Don't turn on errors if this machine is public, as it could potentially 
 give out more information to people than you want. First, look at the error 
 logs for PHP, which record all the errors you've had with the site, whether 
 you have them displayed or not.
   
   
   Thanks,
   Ash
   http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/  
 http://www.ashleysheridan.co.uk/ 
   
   
   
   
 
 
 Have you checked both the PHP and Apache error logs? Things like invalid 
 commands in an .htaccess file can cause server crashes.
 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/ 
 
 
   
 


They could be in a variety of places depending on how your system is set
up. It should show you if you do a phpinfo(); in a page on its own.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Call to undefined method on class property!? - [CLOSED]

2010-01-07 Thread Allen McCabe
I caught that error, but the line number was referring to the assignment, it
didn't even get to the obvious error.

Why would  $total = $db-affected_rows, (assigning the value of
$affected_rows to $total) be interpreted as a method call?

I have since defined a num_rows() method (using mysql_num_rows()) and I have
gotten past this error, however I am still having a major problem with what
I'm trying to accomplish.

I'll post more later tonight when I get home from work... Thanks for your
help Thijs adn Darren

On Thu, Jan 7, 2010 at 3:49 AM, Thijs Lensselink d...@lenss.nl wrote:

 Allen McCabe wrote:

 I have a singleton database object in a global file at the top of my
 document. In most other locations I am able to access it just fine,
 however
 in my footer I want to loop through a properties list for links (I am
 saving
 links to a database, each with its own properties).

 Here is the code snippet that is giving me trouble:

 footerlinks.inc.php:

 ?php
$result = $db-query('SELECT * FROM `links` WHERE `category` =
 \'footer_navigation\';');
$total = $db-affected_rows;


 Here you use affected_rows as a class property to assign a value to a
 variable.



if ($total  0)
{
$Link = new Link();
$count = $db-affected_rows($result);


 Here you call affected_rows as a class method. And from looking at your
 Database class. affected_rows is a property not a method. So that explains
 the undefined method error.



 $i = 0;
while ($row = $db-fetch_array($result))
{
$properties = $Link-setLinkProperties($row);

$link[$i] = 'a ';
foreach ($properties as $prop)
{
$link[$i] .= $prop;
}
$link[$i] .= '';
$row['text'];
$link[$i] .= '/a';

$i++;
}

$j = 0;
while ($j  $link)
{
echo $link[$j];
if ($j  $count)
{
echo ' | ';
}

$j++;
}

}

?

 The $Link-$Link-setLinkProperties() method is defined in

 Link.class.php:

 ?php

 class Link {

public function setLinkProperties($rows)
{
if (!empty($row['href']))
{
$properties['href'] = 'href=' . $row['href'] . ' ';
}

if (!empty($row['class']))
{
$properties['class'] = 'class=' . $row['class'] . ' ';
}

if (!empty($row['style']))
{
$properties['style'] = 'style=' . $row['style'] . ' ';
}

if (!empty($row['title']))
{
$properties['title'] = 'title=' . $row['title'] . ' ';
}

if (!empty($row['name']))
{
$properties['name'] = 'name=' . $row['name'] . ' ';
}

if (!empty($row['target']))
{
$properties['target'] = 'target=' . $row['target'] . ' ';
}

if (!empty($row['rel']))
{
$properties['rel'] = 'rel=' . $row['rel'] . ' ';
}

if (!empty($row['onclick']))
{
$properties['onclick'] = 'onclick=' . $row['onclick'] . ' ';
}

if (!empty($row['ondblclick']))
{
$properties['ondblclick'] = 'ondblclick=' . $row['ondblclick']
 . ' ';
}

if (!empty($row['onmouseover']))
{
$properties['onmouseover'] = 'onmouseover=' .
 $row['onmouseover'] . ' ';
}

if (!empty($row['onmouseout']))
{
$properties['onmouseout'] = 'onmouseout=' . $row['onmouseout']
 . ' ';
}

return $properties;

} // END OF METHOD setLinkProperties
 } // END OF CLASS

 ?

 Also for reference, the method query() in my database class sets a value
 for
 $affected_rows:

 Database.class.php:

 ?php

 class Database {

private $server   = ''; //database server
private $user = ''; //database login name
private $pass = ''; //database login password
private $database = ''; //database name
private $pre  = ''; //table prefix

###
//internal info
private $error = '';
private $errno = 0;

//number of rows affected by SQL query
public $affected_rows = 0;

 ...

 ?

 This is the error I am receiving:

 *Fatal error*: Call to undefined method Database::affected_rows() in *
 /home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*

 Please help PHP gurus!!





Re: [PHP] Re: First time PHP user question

2010-01-07 Thread Jim Lucas
Ashley Sheridan wrote:
 On Thu, 2010-01-07 at 08:32 -0500, Rick Dwyer wrote:
 
 Thanks Ashley  Nathan.

 As it turns out, there is more than one tmp folder... and I was  
 looking in the wrong one.  When I SSH'd in the correct one, I created  
 the missing file and it began to work properly.
 Thanks for chiming in.

 --Rick


 On Jan 7, 2010, at 7:58 AM, Ashley Sheridan wrote:

 On Thu, 2010-01-07 at 09:19 +, Nathan Rixham wrote:
 Rick Dwyer wrote:
 Hello List.
 I have been playing around with PHP, running a few tutorials and  
 I came
 across an error message I could not resolve.

 The tutorial is Generating One Time URL's by Oreilly:
 http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html

 Basically the PHP code is supposed to read from a text file and  
 write to
 a text file and serve a text file all located in the tmp  
 directory of
 the server.

 However, I receive the error that the referenced files in the PHP  
 code
 could not be found:
 Warning: readfile(/tmp/secret_file.txt) [function.readfile]:  
 failed to
 open stream: No such file or directory
 in/home/mysite/myfolder/get_file.php on line 67

 Line 66 and 67 look like this:

 $secretfile = /tmp/secret_file.txt;
 readfile($secretfile);


 However, in the tmp folder, I have created a simple text file  
 called
 secret_file.txt so I know it exists and it has the permissions  
 set to
 644, so it should be readable.

 Can someone point out to me what I am doing wrong?  Thanks,

 try permissions of 777 and see if the error disappears; odds are v  
 high
 that the httpd user php is running under doesn't have group or owner
 permissions for /tmp  that secret file.

 regards


 That shouldn't fix it. 644 permissions allow the owner, group users  
 and anybody else to read file. Have you tried is_file(/tmp/ 
 secret_file.txt); to see if it actually exists? Also, don't forget  
 that Linux is case sensitive when it comes to filenames, so  
 secret_file.txt is completely different from Secret_File.txt, and in- 
 fact you can validly have both in the same directory.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



   --Rick



 
 There isn't more than one /tmp folder, that is impossible. There was
 probably more than one tmp folder, and you weren't looking in the right
 one.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 

Actually, Ash, you can have more then one /tmp folder.  Depends on what app is
looking at it.

If you have PHP running with Apache and Apache is jailed, the the /tmp folder
would be from the perspective to the jail the the actual OS.

So, if apache was jailed to /var/www/ you could then have a /tmp/ and a
/var/www/tmp/

Apache would never see the /tmp/ only the /var/www/tmp/

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



[PHP] cannot access SimpleXML object property

2010-01-07 Thread Mari Masuda
Hi,

I am working with an XML document and have a SimpleXML object whose var_dump 
looks like this:

---
object(SimpleXMLElement)#2 (10) {
  [@attributes]=
  array(1) {
[id]=
string(7) 3854857
  }
  [type]=
  string(7) Article
  [createDate]=
  string(25) 2006-09-06T16:42:20-07:00
  [editDate]=
  string(25) 2007-07-16T09:15:53-07:00
  [creator]=
  string(19) Michael Gottfredson
  [status]=
  string(5) ready
  [field]=
  ...snip a bunch of stuff...
}
---

Assuming the above object is referenced by $current_object, I can access the 
values of most stuff with $current_object-creator or whatever.  However, I 
cannot figure out how to access the value of id.  I tried the following, none 
of which worked for me:

1.  $current_object-@attributes-id (gives Parse error: syntax error, 
unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in 
/Applications/apache/htdocs/test.php on line 33)

2.  $current_object-'@attributes'-id (gives Parse error: syntax error, 
unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' 
or '$' in/Applications/apache/htdocs/test.php on line 33)

3.  $current_object-{...@attributes}-id (no error but is null)

4.  $current_object-{'@attributes'}-id (no error but is also null)

Does anyone know how I can reference the value of id?  Thanks!

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



Re: [PHP] cannot access SimpleXML object property

2010-01-07 Thread Jonathan Tapicer
On Thu, Jan 7, 2010 at 6:56 PM, Mari Masuda mari.mas...@stanford.edu wrote:
 Hi,

 I am working with an XML document and have a SimpleXML object whose var_dump 
 looks like this:

 ---
 object(SimpleXMLElement)#2 (10) {
  [@attributes]=
  array(1) {
    [id]=
    string(7) 3854857
  }
  [type]=
  string(7) Article
  [createDate]=
  string(25) 2006-09-06T16:42:20-07:00
  [editDate]=
  string(25) 2007-07-16T09:15:53-07:00
  [creator]=
  string(19) Michael Gottfredson
  [status]=
  string(5) ready
  [field]=
  ...snip a bunch of stuff...
 }
 ---

 Assuming the above object is referenced by $current_object, I can access the 
 values of most stuff with $current_object-creator or whatever.  However, I 
 cannot figure out how to access the value of id.  I tried the following, none 
 of which worked for me:

 1.  $current_object-@attributes-id (gives Parse error: syntax error, 
 unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in 
 /Applications/apache/htdocs/test.php on line 33)

 2.  $current_object-'@attributes'-id (gives Parse error: syntax error, 
 unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or 
 '{' or '$' in/Applications/apache/htdocs/test.php on line 33)

 3.  $current_object-{...@attributes}-id (no error but is null)

 4.  $current_object-{'@attributes'}-id (no error but is also null)

 Does anyone know how I can reference the value of id?  Thanks!

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




$id = (string)$current_object['id'];

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



Re: [PHP] cannot access SimpleXML object property

2010-01-07 Thread Mari Masuda

On Jan 7, 2010, at 2:31 PM, Jonathan Tapicer wrote:

 On Thu, Jan 7, 2010 at 6:56 PM, Mari Masuda mari.mas...@stanford.edu wrote:
 Hi,
 
 I am working with an XML document and have a SimpleXML object whose var_dump 
 looks like this:
 
 ---
 object(SimpleXMLElement)#2 (10) {
  [@attributes]=
  array(1) {
[id]=
string(7) 3854857
  }
  [type]=
  string(7) Article
  [createDate]=
  string(25) 2006-09-06T16:42:20-07:00
  [editDate]=
  string(25) 2007-07-16T09:15:53-07:00
  [creator]=
  string(19) Michael Gottfredson
  [status]=
  string(5) ready
  [field]=
  ...snip a bunch of stuff...
 }
 ---
 
 Assuming the above object is referenced by $current_object, I can access the 
 values of most stuff with $current_object-creator or whatever.  However, I 
 cannot figure out how to access the value of id.  I tried the following, 
 none of which worked for me:
 
 1.  $current_object-@attributes-id (gives Parse error: syntax error, 
 unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in 
 /Applications/apache/htdocs/test.php on line 33)
 
 2.  $current_object-'@attributes'-id (gives Parse error: syntax error, 
 unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or 
 '{' or '$' in/Applications/apache/htdocs/test.php on line 33)
 
 3.  $current_object-{...@attributes}-id (no error but is null)
 
 4.  $current_object-{'@attributes'}-id (no error but is also null)
 
 Does anyone know how I can reference the value of id?  Thanks!
 
 Mari
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 $id = (string)$current_object['id'];


Thank you.  I also found I could do it with 
$current_object-attributes()-id
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-07 Thread clancy_1
On Wed, 6 Jan 2010 19:11:07 -0800, dae...@daevid.com (Daevid Vincent) wrote:

 

 -Original Message-
 From: Al [mailto:n...@ridersite.org] 
 Sent: Wednesday, January 06, 2010 5:09 PM
 To: php-general@lists.php.net
 Subject: [PHP] Re: PHP programming strategy; lots of little 
 include files, or a few big ones?
 
 
 
 On 1/6/2010 7:18 PM, clanc...@cybec.com.au wrote:
  I have a flexible program, which can do many different 
 things according to the type of
  data it is fed.  Ideally the flexibility is achieved by 
 calling different functions,
  though when the functionality is ill-defined I sometimes 
 just include blocks of code.
 
  Ideally, from the point of program maintenance, each module 
 should not be too long --
  preferably just a page or so. This doesn't raise problems 
 in a compiled language, but in
  an interpreted language like PHP the programmer must decide 
 whether to lump a whole lot of
  functions into a single large include file, or to include 
 lots of little files as the
  particular functions are needed.
 
  The first case can lead to memory bloat, as there are 
 likely to be a lot of unused
  functions in memory on any given pass, whereas the second 
 case may require lots of little
  files to be loaded.
 
  Are there likely to be significant performance costs for 
 either approach, and what are
  your feelings about the relative virtues of the two approaches?

I think it's a case by case basis. Generally File I/O is expensive, but
then again, as you say, having everything in a couple files is also
sub-optimal for organizing and keeping things modular.

I suggest you go with smaller files that are organized into logical
'chunks'. For example, functions that are used frequently are grouped into
a common.inc.php rather than by topic (such as file/date/xml/forms/etc).
And then use topical includes for the rest.

More importantly, I suggest you get a good caching system like memecached
or any of the others out there. Then you can pre-compile and load these
files and the whole point becomes close to moot.

ÐÆ5ÏÐ 
http://daevid.com

Thank you all for your comments. I did not know about bytecode caches. They're 
an
interesting concept, but if I am interpreting the paper
http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly they 
only double
the average speed of operation, which is rather less than I would have 
anticipated. 

As I would have to understand yet another system to implement them, and I 
suspect I'd have
to do a significant amount of rearranging, I don't think I will worry about 
them unless my
webpages unexpectedly become extremely popular.

 Al's suggestion that my code is probably infinitesimal compared with PHP 
suggests that I
shouldn't be worrying about memory requirements.  On the other hand I agree 
with David
that the advantages of using relatively small easy to understand modules 
probably outweigh
the costs of loading a larger number of files.


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



Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-07 Thread clancy_1
On Wed, 06 Jan 2010 23:20:26 -0500, kolb0...@umn.edu (Daniel Kolbo) wrote:

Daevid Vincent wrote:
  
 
 -Original Message-
 From: Al [mailto:n...@ridersite.org] 
 Sent: Wednesday, January 06, 2010 5:09 PM
 To: php-general@lists.php.net
 Subject: [PHP] Re: PHP programming strategy; lots of little 
 include files, or a few big ones?



 On 1/6/2010 7:18 PM, clanc...@cybec.com.au wrote:
 I have a flexible program, which can do many different 
 things according to the type of
 data it is fed.  Ideally the flexibility is achieved by 
 calling different functions,
 though when the functionality is ill-defined I sometimes 
 just include blocks of code.
 Ideally, from the point of program maintenance, each module 
 should not be too long --
 preferably just a page or so. This doesn't raise problems 
 in a compiled language, but in
 an interpreted language like PHP the programmer must decide 
 whether to lump a whole lot of
 functions into a single large include file, or to include 
 lots of little files as the
 particular functions are needed.

 The first case can lead to memory bloat, as there are 
 likely to be a lot of unused
 functions in memory on any given pass, whereas the second 
 case may require lots of little
 files to be loaded.

 Are there likely to be significant performance costs for 
 either approach, and what are
 your feelings about the relative virtues of the two approaches?
 
 I think it's a case by case basis. Generally File I/O is expensive, but
 then again, as you say, having everything in a couple files is also
 sub-optimal for organizing and keeping things modular.
 
 I suggest you go with smaller files that are organized into logical
 'chunks'. For example, functions that are used frequently are grouped into
 a common.inc.php rather than by topic (such as file/date/xml/forms/etc).
 And then use topical includes for the rest.
 
 More importantly, I suggest you get a good caching system like memecached
 or any of the others out there. Then you can pre-compile and load these
 files and the whole point becomes close to moot.
 
 ÐÆ5ÏÐ 
 http://daevid.com
 
 Some people, when confronted with a problem, think 'I know, I'll use
 XML.'
 Now they have two problems. 
 
 

I had a similar issue but with classes (not functions).
I opted to keep my classes short and succinct, rather than shoving all
the method functionality into one all-purpose class.
Instead of blindly loading all the little classes on each http request,
I used (and was recommended on this list to use) __autoload().  The
script would only load my classes if the individual request needed it.
This helped to avoid the memory bloat.  I've heard magic functions like
__autoload are a bit slower, but the code is so much cleaner b/c of it.

Also, an opcode cache as suggested previously would facilitate the rapid
include of many small files.

Unfortunately, php does not offer an __autoload() type function to
autoload functions.

If you are able to encapsulate your functions functionality into classes
you may be able to use the above solution of using an opcode cache to
help __autoload() a bunch of small classes.

Although PHP doesn't offer an _autoload() function to autoload functions, it 
does provide
function_exists, and this can readily be used to achieve the same end:

If (!function_exists(feedback_handler)) { include 
('Feedback_handler.php'); }

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



RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no longer working

2010-01-07 Thread Vernon Webb
It's the oddest thing. I've found the logs but there is no error at all, the 
server just hangs and the only way to get it back is to restart Apache.
 



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: Thu 1/7/2010 9:04 AM
To: Vernon Webb
Cc: php-general@lists.php.net
Subject: RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, location no 
longer working


On Thu, 2010-01-07 at 08:57 -0500, Vernon Webb wrote: 

Didn't know there were php logs, I thought they would be included in 
the Apache logs, where do I find the php logs?
 
~V



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: Thu 1/7/2010 8:42 AM
To: Vernon Webb
Cc: php-general@lists.php.net
Subject: RE: [PHP] Site Moved From PHP4 to PHP5 Server - header, 
location no longer working


On Thu, 2010-01-07 at 08:40 -0500, Vernon Webb wrote: 

That's the odd thing, there is nothing being indicated in the 
error logs the server just hangs and I have to restart apache in order to get 
the site back up. First I thought it might be the server so I move over to a 
different server, but I still have the same issue. What I feel is really odd is 
the fact that it worked in a previous version of php, so waht's changed?
 
~V



From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
Sent: Thu 1/7/2010 7:52 AM
To: James McLean
Cc: Vernon Webb; php-general@lists.php.net
Subject: Re: [PHP] Site Moved From PHP4 to PHP5 Server - 
header, location no longer working


On Thu, 2010-01-07 at 16:50 +1030, James McLean wrote: 

On Thu, Jan 7, 2010 at 1:35 PM, Vernon Webb 
ver...@comp-wiz.com wrote:
 I move a number of sites from one server to another 
and one the one server we had php4 and now we have php5 and since then my 
server seems to hang every time there is a header, location redirect. Anyone 
have any ideas on how to resolve this? Is there something I can easily change 
in the php.ini file that will resolve this issue?

Off the top of my head it sounds like something is 
being output before
the header, which causes an error. If you also have 
error display
turned off, you will likely just see a white screen 
with no useful
information.

Make sure none of your includes have trailing 
whitespace or are trying
to print out information before the header itself.

Best bet is to turn on errors and log them, then you 
will see where
the output started if infact that is your issue.

Cheers



Don't turn on errors if this machine is public, as it could 
potentially give out more information to people than you want. First, look at 
the error logs for PHP, which record all the errors you've had with the site, 
whether you have them displayed or not.


Thanks,
Ash
http://www.ashleysheridan.co.uk 
http://www.ashleysheridan.co.uk/  http://www.ashleysheridan.co.uk/  
http://www.ashleysheridan.co.uk/ 






Have you checked both the PHP and Apache error logs? Things like 
invalid commands in an .htaccess file can cause server crashes.


Thanks,
Ash
http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/  
http://www.ashleysheridan.co.uk/ 






They could be in a variety of places depending on how your system is set up. It 
should show you if you do a phpinfo(); in a page on its own.


Thanks,
Ash
http://www.ashleysheridan.co.uk http://www.ashleysheridan.co.uk/ 




-- 
This message has been scanned for viruses and 
dangerous content by comp-wiz.com http://comp-wiz.com/ , and is 
believed to be clean. 


Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-07 Thread Robert Cummings

clanc...@cybec.com.au wrote:

Thank you all for your comments. I did not know about bytecode caches. They're 
an
interesting concept, but if I am interpreting the paper
http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly they 
only double
the average speed of operation, which is rather less than I would have anticipated. 


I strongly advise that you take the time to try a bytecode cache. Within 
linux environments I am partial to eaccelerator. In IIS environments I 
now use WinCache from Microsoft. From my own observations with a 
multitude of different types of PHP web applications I find that the 
speed gain is closer to 5 times faster on average.



As I would have to understand yet another system to implement them, and I 
suspect I'd have
to do a significant amount of rearranging, I don't think I will worry about 
them unless my
webpages unexpectedly become extremely popular.


That's your perogative, but you started this thread with a question 
about file access times. By your latest argument (above) you may as well 
ignore it since when and if the issue becomes salient then you can worry 
about it. However, I think that's disingenuous at best since your pages 
will appear slower on average, and you're just wasting CPU resources.



Al's suggestion that my code is probably infinitesimal compared with PHP 
suggests that I
shouldn't be worrying about memory requirements.  On the other hand I agree 
with David
that the advantages of using relatively small easy to understand modules 
probably outweigh
the costs of loading a larger number of files.


You've missed several points. Bytecode caches allow you to skip the trip 
to the filesystem. They allow you to skip the parse and compile stage of 
PHP. They almost always make your shit run faster.


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

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



Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-07 Thread clancy_1
On Thu, 07 Jan 2010 22:48:59 -0500, rob...@interjinn.com (Robert Cummings) 
wrote:

clanc...@cybec.com.au wrote:
 Thank you all for your comments. I did not know about bytecode caches. 
 They're an
 interesting concept, but if I am interpreting the paper
 http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly they 
 only double
 the average speed of operation, which is rather less than I would have 
 anticipated. 

I strongly advise that you take the time to try a bytecode cache. Within 
linux environments I am partial to eaccelerator. In IIS environments I 
now use WinCache from Microsoft. From my own observations with a 
multitude of different types of PHP web applications I find that the 
speed gain is closer to 5 times faster on average.

Five times faster is certainly more attractive than twice as fast. But under 
what
circumstances is this achieved? Unfortunately these days it is difficult to 
find any solid
information on how things actually work, but my impression is that caches only 
work for
pages which are frequently accessed. If this is correct, and (as I suspect) 
somebody looks
at my website once an hour, the page will not be in the cache, so it won't 
help. Also one
of the more popular parts of this website is my photo album, and for this much 
of the
access time will be the download time of the photos. Furthermore as each 
visitor will look
at a different set of photos, even with heavy access it is unlikely that any 
given photo
would be in a cache. 

Despite these comments the access times for my websites seem to be pretty good 
--
certainly a lot better than many commercial websites -- but have a look at
http://www.corybas.com/, and see what you think. (I am in the process of 
updating this,
and know that the technical notes are not currently working, but there is 
plenty there to
show you what I'm trying to do.)

 As I would have to understand yet another system to implement them, and I 
 suspect I'd have
 to do a significant amount of rearranging, I don't think I will worry about 
 them unless my
 webpages unexpectedly become extremely popular.

That's your perogative, but you started this thread with a question 
about file access times. By your latest argument (above) you may as well 
ignore it since when and if the issue becomes salient then you can worry 
about it. However, I think that's disingenuous at best since your pages 
will appear slower on average, and you're just wasting CPU resources.

Unfortunately I am cursed with an insatiable curiosity, and spend far too much 
time
thinking about philosophical questions like this. But I have also been 
programming almost
forever, and I have learned that it would now take me five times as long as (I 
hope) it
would take you to implement something new like byte code caching.

 Al's suggestion that my code is probably infinitesimal compared with PHP 
 suggests that I
 shouldn't be worrying about memory requirements.  On the other hand I agree 
 with David
 that the advantages of using relatively small easy to understand modules 
 probably outweigh
 the costs of loading a larger number of files.

You've missed several points. Bytecode caches allow you to skip the trip 
to the filesystem. They allow you to skip the parse and compile stage of 
PHP. They almost always make your shit run faster.

Perhaps. But my visitors appear to be happy now, and my hosts aren't 
complaining that I'm
overloading their system.

Clancy

PS. It does sadden me that there don't seem to be many people here who are 
interested in
the philosophy of programming, as against the quick and dirty fix.


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