[PHP] problem with download script on safari and ie 7

2007-10-08 Thread Hulf
The problem I am getting is safari just downloads the .php file. IE7 
corrupts the binary file. It opens fine on FF and IE6. Is this a headers 
problem?

Thanks,


R.


http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with download script on safari and ie 7

2007-10-08 Thread Robert Cummings
On Mon, 2007-10-08 at 14:59 +0100, Hulf wrote:
> The problem I am getting is safari just downloads the .php file. IE7 
> corrupts the binary file. It opens fine on FF and IE6. Is this a headers 
> problem?

What's the value of $type?

Cheers,
Rob.

> 
> Thanks,
> 
> 
> R.
> 
> 
>  
> if(isset($_GET['id']))
> {
> 
> 
> $id= $_GET['id'];
> $query = "SELECT file_name, type, size, content FROM results WHERE id
> = 
> '$id'";
> 
> $result = mysql_query($query) or die(mysql_error());;
> list($file_name, $type, $size, $content) = 
> mysql_fetch_array($result);
> 
> /*echo $file_name;
> echo $type;
> echo $size;*/
> 
> 
> header("Content-Type: $type");
> header("Content-Disposition: attachment; filename=$file_name");
> header("Content-Length: ".filesize($file));
> header("Accept-Ranges: bytes");
> header("Pragma: no-cache");
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Content-transfer-encoding: binary");
> 
> echo $content;
> exit; 
> 
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



[PHP] Re: problem with download script on safari and ie 7

2007-10-08 Thread Hulf
I changes it now so it is...

header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=$file_name");
echo $content;
exit;


Which works on ie7 but safari still downloads the .php

R.


""Hulf"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> The problem I am getting is safari just downloads the .php file. IE7 
> corrupts the binary file. It opens fine on FF and IE6. Is this a headers 
> problem?
>
> Thanks,
>
>
> R.
>
>
> 
> if(isset($_GET['id']))
> {
>
>
> $id= $_GET['id'];
> $query = "SELECT file_name, type, size, content FROM results WHERE id = 
> '$id'";
>
> $result = mysql_query($query) or die(mysql_error());;
> list($file_name, $type, $size, $content) = mysql_fetch_array($result);
>
> /*echo $file_name;
> echo $type;
> echo $size;*/
>
>
> header("Content-Type: $type");
> header("Content-Disposition: attachment; filename=$file_name");
> header("Content-Length: ".filesize($file));
> header("Accept-Ranges: bytes");
> header("Pragma: no-cache");
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Content-transfer-encoding: binary");
>
> echo $content;
> exit; 

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



Re: [PHP] Please recommend blog script

2007-10-08 Thread Richard S. Crawford
On Sunday 07 October 2007 03:41:40 Paul Scott wrote:
> On Sun, 2007-10-07 at 09:35 +0200, Niels wrote:
> > Basically I want to integrate articles into existing pages, something
> > like 
> > 
>
> What you want is a blog that exposes it's functionality as an API
> (MetaWebLog or ATOM). Most do that, including the Chisimba one (see
> http://fsiu.uwc.ac.za as an example. Download at http://avoir.uwc.ac.za)
>
> --Paul

I've used Wordpress like that on my own site.  I have my blog set up in one 
directory, but I use WordPress's API throughout my site to keep things 
consistent.

-- 
Richard S. Crawford
Editor-in-chief, Daikaijuzine (http://www.daikaijuzine.com)
Personal website: http://www.mossroot.com
http://www.myspace.com/underpope / underpope.livejournal.com
"We are here to help each other get through this thing, whatever it is."
(Kurt Vonnegut, 1922 - 2007)

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



Re: [PHP] Moodle: Add field to user listing

2007-10-08 Thread Richard S. Crawford
On Sunday 07 October 2007 08:10:16 RalfGesellensetter wrote:
> Dear list,
>
> is there any approach to patch any PHP files within moodle in order to
> gain further columns for the user list?
>
> Reference: http://docs.moodle.org/en/Browse_list_of_users
>
> Objective: I wish to add a (sortable) user field in order to find users
> by additional aspects.
>
> Thanks
> Ralf

Ralf,

As Tom suggested, your best bet is to go to Moodle.org and ask on the forums 
there.

Having said that, I'd be remiss if I didn't mention that starting with 1.7, 
Moodle allows for custom fields in user records.  I haven't yet worked with 
this functionality myself so I don't know much about it, but it's definitely 
there.  Again, query the forums on http://www.moodle.org.

-- 
Richard S. Crawford
Editor-in-chief, Daikaijuzine (http://www.daikaijuzine.com)
Personal website: http://www.mossroot.com
http://www.myspace.com/underpope / underpope.livejournal.com
"We are here to help each other get through this thing, whatever it is."
(Kurt Vonnegut, 1922 - 2007)


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] problem with download script on safari and ie 7

2007-10-08 Thread Jim Lucas

Hulf wrote:

header("Content-Length: ".filesize($file));


Ok, for the third time, I am going to ask, why are you running filesize() on a variable that doesn't 
exist.  You are pulling a variable out of the DB called $size.  From the scripts that you posted a 
few weeks ago, the upload handling script showed this $size column was the actual size of data.  So, 
just use $size instead of an undefined variable.




--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



RE: [PHP] Something you can do with AJAX + PHP as well

2007-10-08 Thread Jay Blanchard
[snip]
I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:
http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration
%20with%20AJAX.mpeg

Cool huh?
[/snip]

It is too bad that the video does not play. 

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



Re: [PHP] Something you can do with AJAX + PHP as well

2007-10-08 Thread Jim Lucas

Mark wrote:

Hey,

I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:
http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration%20with%20AJAX.mpeg

Cool huh?

Mark.


Same as Jay here, it doesn't play for me either.

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Something you can do with AJAX + PHP as well

2007-10-08 Thread Tom Friedhof
I had to download the video and open it up in VLC to play.  I'm on Mac OS X,
not sure what windows program will open it.

Tom Friedhof

On 10/8/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
>
> Mark wrote:
> > Hey,
> >
> > I've made a nice video where you see ajax in combination with php. and
> > it works really well although really is misspelled "realy".
> >
> > Here is the video:
> >
> http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration%20with%20AJAX.mpeg
> >
> > Cool huh?
> >
> > Mark.
> >
> Same as Jay here, it doesn't play for me either.
>
> --
> Jim Lucas
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>  by William Shakespeare
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Something you can do with AJAX + PHP as well

2007-10-08 Thread Stut

Tom Friedhof wrote:

I had to download the video and open it up in VLC to play.  I'm on Mac OS X,
not sure what windows program will open it.


I'm thinking VLC might. Is it worth it?

-Stut


On 10/8/07, Jim Lucas <[EMAIL PROTECTED]> wrote:

Mark wrote:

Hey,

I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:


http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration%20with%20AJAX.mpeg

Cool huh?

Mark.


Same as Jay here, it doesn't play for me either.

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
 by William Shakespeare

--
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] Something you can do with AJAX + PHP as well

2007-10-08 Thread Jay Blanchard
[snip]
I saved it and it played in Winamp, but no audio
[/snip]

So, is it worth going to all of the trouble to see? 

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



Re: [PHP] Something you can do with AJAX + PHP as well

2007-10-08 Thread Jim Lucas

Stut wrote:

Tom Friedhof wrote:
I had to download the video and open it up in VLC to play.  I'm on Mac 
OS X,

not sure what windows program will open it.


I'm thinking VLC might. Is it worth it?

-Stut


On 10/8/07, Jim Lucas <[EMAIL PROTECTED]> wrote:

Mark wrote:

Hey,

I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:

http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration%20with%20AJAX.mpeg 


Cool huh?

Mark.


Same as Jay here, it doesn't play for me either.

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
 by William Shakespeare

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








I saved it and it played in Winamp, but no audio

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] Socket how to die if connection broken

2007-10-08 Thread chris

Hi I have a socket connection like so..

$sourceip = '84.234.18.16'; // ip you want to bind to

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $sourceip);
socket_connect($sock, 'dac.nic.uk', 2043);

if ($socket === false) {
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);
   
   die("Couldn't create socket: [$errorcode] $errormsg");

}


But if the socket connection gets broken it creates an error msg 


Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in

That spills out for thousands and thousands of lines.

What would I need for the script to die if the connection gets broken.

Thanks

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



Re: [PHP] Socket how to die if connection broken

2007-10-08 Thread Stut

[EMAIL PROTECTED] wrote:

Hi I have a socket connection like so..

$sourceip = '84.234.18.16'; // ip you want to bind to

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $sourceip);
socket_connect($sock, 'dac.nic.uk', 2043);

if ($socket === false) {
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);
  die("Couldn't create socket: [$errorcode] $errormsg");
}


But if the socket connection gets broken it creates an error msg
Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in

That spills out for thousands and thousands of lines.

What would I need for the script to die if the connection gets broken.


This has nothing to do with opening the socket. When you are writing to 
the socket you need something like this...


if (false === @socket_write($s, $buffer))
{
// In here you know something is wrong. Use socket_last_error() to
// find out what and deal with it appropriately. Bear in mind that
// socket_write can fail for lots of reasons, not just a broken
// pipe so you need to check what error occurred before you can
// know what to do with it.
}

Note that you should never use the @ operator unless you are absolutely 
sure you're handling any potential errors correctly.


-Stut

--
http://stut.net/

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



RE: [PHP] Socket how to die if connection broken

2007-10-08 Thread Instruct ICC

> But if the socket connection gets broken it creates an error msg 
> 
> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> 
> That spills out for thousands and thousands of lines.
> 
> What would I need for the script to die if the connection gets broken.

It's just sitting around, gets broken, then outputs those errors?

Do you check that it is a valid socket before you attempt a write?

_
Windows Live Hotmail and Microsoft Office Outlook – together at last.  Get it 
now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033

Re: [PHP] Socket how to die if connection broken

2007-10-08 Thread chris

Yes its a valid socket.

The destination only allows a max of 2 two connections at any one time. The
most likely
reason for lossing a connection is I exceed the 2 connection rule and then
it breaks and
spills out that error.


- Original Message - 
From: "Instruct ICC" <[EMAIL PROTECTED]>

To: 
Sent: Monday, October 08, 2007 5:27 PM
Subject: RE: [PHP] Socket how to die if connection broken




But if the socket connection gets broken it creates an error msg

Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in

That spills out for thousands and thousands of lines.

What would I need for the script to die if the connection gets broken.


It's just sitting around, gets broken, then outputs those errors?

Do you check that it is a valid socket before you attempt a write?

_
Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it 
now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033 


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



[PHP] PHP5 under IIS6

2007-10-08 Thread Alberto García Gómez

Hi fellows:

I'm trying to mount PHP5 ( the last stable version from php.net) under a 
IIS6 (win2k3 SP2), and when I run the .msi and it finish it said that is not 
possible the configure httpd.conf, which is a very big mistake 'cause I'm 
specify that I use IIS6.


After that I try making a manual configuration and I recive a CGI error.

I need help ASAP. 



Este correo ha sido enviado desde el Politécnico de Informática "Carlos Marx" 
de Matanzas.
"La gran batalla se librará en el campo de las ideas"

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



Re: [PHP] Socket how to die if connection broken

2007-10-08 Thread chris

Hi Stut Ive tried your example but still cant get it to work.

- Original Message - 
From: "Stut" <[EMAIL PROTECTED]>

To: <[EMAIL PROTECTED]>
Cc: 
Sent: Monday, October 08, 2007 5:26 PM
Subject: Re: [PHP] Socket how to die if connection broken



[EMAIL PROTECTED] wrote:

Hi I have a socket connection like so..

$sourceip = '84.234.18.16'; // ip you want to bind to

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $sourceip);
socket_connect($sock, 'dac.nic.uk', 2043);

if ($socket === false) {
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);
  die("Couldn't create socket: [$errorcode] $errormsg");
}


But if the socket connection gets broken it creates an error msg
Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in
Warning: socket_write(): unable to write to socket [32]: Broken pipe in

That spills out for thousands and thousands of lines.

What would I need for the script to die if the connection gets broken.


This has nothing to do with opening the socket. When you are writing to 
the socket you need something like this...


if (false === @socket_write($s, $buffer))
{
// In here you know something is wrong. Use socket_last_error() to
// find out what and deal with it appropriately. Bear in mind that
// socket_write can fail for lots of reasons, not just a broken
// pipe so you need to check what error occurred before you can
// know what to do with it.
}

Note that you should never use the @ operator unless you are absolutely 
sure you're handling any potential errors correctly.


-Stut

--
http://stut.net/

--
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] PHP5 under IIS6

2007-10-08 Thread Carlton Whitehead
Hi Alberto,

Try using the php5isapi.dll instead of CGI.  Make sure you have an entry for 
PHP5 in your Web Service Extensions list, and that it is marked as Allowed.  
Also, open the properties of your Web Sites folder in IIS Manager, go to the 
Home Directory Tab, click Configuration, and make sure the php5isapi.dll is 
mapped to the .php extension.

Regards,
Carlton Whitehead

- Original Message -
From: "Alberto García Gómez" <[EMAIL PROTECTED]>
To: php-general@lists.php.net
Sent: Monday, October 8, 2007 9:57:42 AM (GMT-0500) America/New_York
Subject: [PHP] PHP5 under IIS6

Hi fellows:

I'm trying to mount PHP5 ( the last stable version from php.net) under a 
IIS6 (win2k3 SP2), and when I run the .msi and it finish it said that is not 
possible the configure httpd.conf, which is a very big mistake 'cause I'm 
specify that I use IIS6.

After that I try making a manual configuration and I recive a CGI error.

I need help ASAP. 


Este correo ha sido enviado desde el Politécnico de Informática "Carlos Marx" 
de Matanzas.
"La gran batalla se librará en el campo de las ideas"

-- 
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] Structure of maintainable websites

2007-10-08 Thread Matheus Degiovani

Hello,

I'm currently maintaining a website (I developed myself) for the 
Intranet of a public school. Among the usual things (news, login system, 
online grading) the web interface is also used for controlling the 
server it resides on (which includes a few simple tasks such as 
verifying the UPS load, adding users, editing a few conf files) and also 
it is used for (actually, the main purpose of it) 
enabling/restricting/disabling internet access to each of our computer labs.


The system started quite small (since it had to be built fast), but is 
starting to grow to incorporate new features. Currently, each function 
of the system is built in a different php file. It doesn't use any 
template system, though all shared functions are stored in several files 
in a /lib directory and imported in an as-needed basis. Some of the 
libraries are third party, so some are strictly funcional, others are 
Object-Oriented.


I have worked with a few CMSs in the past, indeed I even wrote plugins 
for some, so I have *some* idea of application design in PHP. However, 
I'd like a few pointers on how to make a good, solid infrastructure for 
my code (possibly a complete redesign) which allows it to be easily 
maintained by future analists. Would using Smarty be the best solution, 
in this case? Personally, I wouldn't like to tie the system with any 
existing CMS.


So, my question is: are there any good practices that I should be aware 
of or example websites I can study, that will give me the knowledge I 
need? I'm not looking for references on general software design 
approaches, but practical information on how to apply them to PHP websites.


Thanks,
Matheus Degiovani.

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



[PHP] triggering another php script whilst parent continues

2007-10-08 Thread chris
Hi how would I trigger another script whilst the parent continues without 
waiting for the second script
to finish. ie in the example below if db empty, start second script but also 
continue closing connections

and exiting.

if(sqlite_num_rows($result) == 0)
{

// trigger another php script

sqlite_close($db);
socket_close($sock);
exit;

}

Thanks


- Original Message - 
From: "Alberto García Gómez" <[EMAIL PROTECTED]>

To: 
Sent: Monday, October 08, 2007 2:57 PM
Subject: [PHP] PHP5 under IIS6



Hi fellows:

I'm trying to mount PHP5 ( the last stable version from php.net) under a 
IIS6 (win2k3 SP2), and when I run the .msi and it finish it said that is 
not possible the configure httpd.conf, which is a very big mistake 'cause 
I'm specify that I use IIS6.


After that I try making a manual configuration and I recive a CGI error.

I need help ASAP.

Este correo ha sido enviado desde el Politécnico de Informática "Carlos 
Marx" de Matanzas.

"La gran batalla se librará en el campo de las ideas"

--
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] Socket how to die if connection broken

2007-10-08 Thread Instruct ICC

Remove the @ and see if you get any useful message.

> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> CC: php-general@lists.php.net
> Date: Mon, 8 Oct 2007 19:04:45 +0100
> Subject: Re: [PHP] Socket how to die if connection broken
> 
> Hi Stut Ive tried your example but still cant get it to work.
> 
> - Original Message - 
> From: "Stut" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Cc: 
> Sent: Monday, October 08, 2007 5:26 PM
> Subject: Re: [PHP] Socket how to die if connection broken
> 
> 
> > [EMAIL PROTECTED] wrote:
> >> Hi I have a socket connection like so..
> >> 
> >> $sourceip = '84.234.18.16'; // ip you want to bind to
> >> 
> >> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
> >> socket_bind($sock, $sourceip);
> >> socket_connect($sock, 'dac.nic.uk', 2043);
> >> 
> >> if ($socket === false) {
> >>$errorcode = socket_last_error();
> >>$errormsg = socket_strerror($errorcode);
> >>   die("Couldn't create socket: [$errorcode] $errormsg");
> >> }
> >> 
> >> 
> >> But if the socket connection gets broken it creates an error msg
> >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> >> 
> >> That spills out for thousands and thousands of lines.
> >> 
> >> What would I need for the script to die if the connection gets broken.
> > 
> > This has nothing to do with opening the socket. When you are writing to 
> > the socket you need something like this...
> > 
> > if (false === @socket_write($s, $buffer))
> > {
> > // In here you know something is wrong. Use socket_last_error() to
> > // find out what and deal with it appropriately. Bear in mind that
> > // socket_write can fail for lots of reasons, not just a broken
> > // pipe so you need to check what error occurred before you can
> > // know what to do with it.
> > }
> > 
> > Note that you should never use the @ operator unless you are absolutely 
> > sure you're handling any potential errors correctly.
> > 
> > -Stut
> > 
> > -- 
> > http://stut.net/
> > 
> > -- 
> > 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
> 

_
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews

[PHP] count vs mysql_num_rows

2007-10-08 Thread Kevin Murphy
I've got a little function that just checks to see if something is in  
a mysql db. There are several ways to do this and was curious as to  
the best way. The following are 2 (simplified) versions that work  
just fine. If these are the best ways, which of the following is  
better from a performance standpoint. And if there is a way that is  
better than one of these, I'd love to know what that is.


$query = "SELECT count(id) as count FROM wncci_intranet.iAdmin_users  
WHERE name = '$name' LIMIT 1";

$results = mysql_query($query);
$row = mysql_fetch_array($results);
$count = $row["count"];
return $count;

OR

$query = "SELECT id FROM wncci_intranet.iAdmin_users WHERE name =  
'$name' LIMIT 1";

$results = mysql_query($query);
$count = mysql_num_rows($results);
return $count;


Thanks.

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326

P.S. Please note that my e-mail and website address have changed from  
wncc.edu to wnc.edu.





Re: [PHP] Socket how to die if connection broken

2007-10-08 Thread chris

Hi I got this error

Warning: socket_write() expects parameter 1 to be resource, null given in 
/path/script.php on line 34


Thanks

- Original Message - 
From: "Instruct ICC" <[EMAIL PROTECTED]>

To: 
Sent: Monday, October 08, 2007 7:43 PM
Subject: RE: [PHP] Socket how to die if connection broken



Remove the @ and see if you get any useful message.


From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
CC: php-general@lists.php.net
Date: Mon, 8 Oct 2007 19:04:45 +0100
Subject: Re: [PHP] Socket how to die if connection broken

Hi Stut Ive tried your example but still cant get it to work.

- Original Message - 
From: "Stut" <[EMAIL PROTECTED]>

To: <[EMAIL PROTECTED]>
Cc: 
Sent: Monday, October 08, 2007 5:26 PM
Subject: Re: [PHP] Socket how to die if connection broken


> [EMAIL PROTECTED] wrote:
>> Hi I have a socket connection like so..
>>
>> $sourceip = '84.234.18.16'; // ip you want to bind to
>>
>> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
>> socket_bind($sock, $sourceip);
>> socket_connect($sock, 'dac.nic.uk', 2043);
>>
>> if ($socket === false) {
>>$errorcode = socket_last_error();
>>$errormsg = socket_strerror($errorcode);
>>   die("Couldn't create socket: [$errorcode] $errormsg");
>> }
>>
>>
>> But if the socket connection gets broken it creates an error msg
>> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
>> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
>> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
>>
>> That spills out for thousands and thousands of lines.
>>
>> What would I need for the script to die if the connection gets broken.
>
> This has nothing to do with opening the socket. When you are writing to
> the socket you need something like this...
>
> if (false === @socket_write($s, $buffer))
> {
> // In here you know something is wrong. Use socket_last_error() to
> // find out what and deal with it appropriately. Bear in mind that
> // socket_write can fail for lots of reasons, not just a broken
> // pipe so you need to check what error occurred before you can
> // know what to do with it.
> }
>
> Note that you should never use the @ operator unless you are absolutely
> sure you're handling any potential errors correctly.
>
> -Stut
>
> -- 
> http://stut.net/

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



_
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews 


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



Re: [PHP] Socket how to die if connection broken

2007-10-08 Thread chris

Sorry if I change it to..

if (false === socket_write($sock, $buffer))

rather then $s

if (false === socket_write($s, $buffer))

ie

if (false === socket_write($sock, $buffer))
{
echo "connection broken";
socket_close($sock);
exit;
}

I dont get that error

Warning: socket_write() expects parameter 1 to be resource, null given in
/path/script.php on line 34

but just the original error msg

Warning: socket_write(): unable to write to socket [32]: Broken pipe in

Thanks




- Original Message - 
From: "Instruct ICC" <[EMAIL PROTECTED]>

To: 
Sent: Monday, October 08, 2007 7:43 PM
Subject: RE: [PHP] Socket how to die if connection broken



Remove the @ and see if you get any useful message.


From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
CC: php-general@lists.php.net
Date: Mon, 8 Oct 2007 19:04:45 +0100
Subject: Re: [PHP] Socket how to die if connection broken

Hi Stut Ive tried your example but still cant get it to work.

- Original Message - 
From: "Stut" <[EMAIL PROTECTED]>

To: <[EMAIL PROTECTED]>
Cc: 
Sent: Monday, October 08, 2007 5:26 PM
Subject: Re: [PHP] Socket how to die if connection broken


> [EMAIL PROTECTED] wrote:
>> Hi I have a socket connection like so..
>>
>> $sourceip = '84.234.18.16'; // ip you want to bind to
>>
>> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
>> socket_bind($sock, $sourceip);
>> socket_connect($sock, 'dac.nic.uk', 2043);
>>
>> if ($socket === false) {
>>$errorcode = socket_last_error();
>>$errormsg = socket_strerror($errorcode);
>>   die("Couldn't create socket: [$errorcode] $errormsg");
>> }
>>
>>
>> But if the socket connection gets broken it creates an error msg
>> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
>> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
>> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
>>
>> That spills out for thousands and thousands of lines.
>>
>> What would I need for the script to die if the connection gets broken.
>
> This has nothing to do with opening the socket. When you are writing to
> the socket you need something like this...
>
> if (false === @socket_write($s, $buffer))
> {
> // In here you know something is wrong. Use socket_last_error() to
> // find out what and deal with it appropriately. Bear in mind that
> // socket_write can fail for lots of reasons, not just a broken
> // pipe so you need to check what error occurred before you can
> // know what to do with it.
> }
>
> Note that you should never use the @ operator unless you are absolutely
> sure you're handling any potential errors correctly.
>
> -Stut
>
> -- 
> http://stut.net/

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



_
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews 


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



Re: [PHP] count vs mysql_num_rows

2007-10-08 Thread mike
On 10/8/07, Kevin Murphy <[EMAIL PROTECTED]> wrote:
> I've got a little function that just checks to see if something is in
> a mysql db. There are several ways to do this and was curious as to
> the best way. The following are 2 (simplified) versions that work
> just fine. If these are the best ways, which of the following is
> better from a performance standpoint. And if there is a way that is
> better than one of these, I'd love to know what that is.

> $query = "SELECT count(id) as count FROM wncci_intranet.iAdmin_users
> WHERE name = '$name' LIMIT 1";
> $results = mysql_query($query);
> $row = mysql_fetch_array($results);
> $count = $row["count"];
> return $count;
>
> OR
>
> $query = "SELECT id FROM wncci_intranet.iAdmin_users WHERE name =
> '$name' LIMIT 1";
> $results = mysql_query($query);
> $count = mysql_num_rows($results);
> return $count;

i would do a select count() from the database. no sense in returning
all the row data back to the script just to do a count on it there.
that's additional network/socket transfer between the app and the
database, then processing on the app side to collect all the rows into
memory, etc.

you also don't need to do select count(id) as count, just do a select
count(id) and do a mysql_fetch_array($results, MYSQL_NUM) or
mysql_fetch_row($results) - you don't need to make it an associative
array, since it's only one column and the name is irrelevant.

mysql_fetch_row() is the best function for what you want. you'll save
any additional PHP overhead with different types of arrays being
setup.

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



RE: [PHP] Socket how to die if connection broken

2007-10-08 Thread Instruct ICC

It looks like you didn't pass in a socket resource as the first parameter to 
socket_write.
http://php.he.net/manual/en/function.socket-write.php

> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]; php-general@lists.php.net
> Date: Mon, 8 Oct 2007 19:51:15 +0100
> Subject: Re: [PHP] Socket how to die if connection broken
> 
> Hi I got this error
> 
> Warning: socket_write() expects parameter 1 to be resource, null given in 
> /path/script.php on line 34
> 
> Thanks
> 
> - Original Message - 
> From: "Instruct ICC" <[EMAIL PROTECTED]>
> To: 
> Sent: Monday, October 08, 2007 7:43 PM
> Subject: RE: [PHP] Socket how to die if connection broken
> 
> 
> 
> Remove the @ and see if you get any useful message.
> 
> > From: [EMAIL PROTECTED]
> > To: [EMAIL PROTECTED]
> > CC: php-general@lists.php.net
> > Date: Mon, 8 Oct 2007 19:04:45 +0100
> > Subject: Re: [PHP] Socket how to die if connection broken
> >
> > Hi Stut Ive tried your example but still cant get it to work.
> >
> > - Original Message - 
> > From: "Stut" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Cc: 
> > Sent: Monday, October 08, 2007 5:26 PM
> > Subject: Re: [PHP] Socket how to die if connection broken
> >
> >
> > > [EMAIL PROTECTED] wrote:
> > >> Hi I have a socket connection like so..
> > >>
> > >> $sourceip = '84.234.18.16'; // ip you want to bind to
> > >>
> > >> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
> > >> socket_bind($sock, $sourceip);
> > >> socket_connect($sock, 'dac.nic.uk', 2043);
> > >>
> > >> if ($socket === false) {
> > >>$errorcode = socket_last_error();
> > >>$errormsg = socket_strerror($errorcode);
> > >>   die("Couldn't create socket: [$errorcode] $errormsg");
> > >> }
> > >>
> > >>
> > >> But if the socket connection gets broken it creates an error msg
> > >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> > >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> > >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in
> > >>
> > >> That spills out for thousands and thousands of lines.
> > >>
> > >> What would I need for the script to die if the connection gets broken.
> > >
> > > This has nothing to do with opening the socket. When you are writing to
> > > the socket you need something like this...
> > >
> > > if (false === @socket_write($s, $buffer))
> > > {
> > > // In here you know something is wrong. Use socket_last_error() to
> > > // find out what and deal with it appropriately. Bear in mind that
> > > // socket_write can fail for lots of reasons, not just a broken
> > > // pipe so you need to check what error occurred before you can
> > > // know what to do with it.
> > > }
> > >
> > > Note that you should never use the @ operator unless you are absolutely
> > > sure you're handling any potential errors correctly.
> > >
> > > -Stut
> > >
> > > -- 
> > > http://stut.net/
> > >
> > > -- 
> > > 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
> >
> 
> _
> Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
> http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews
>  
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_
Help yourself to FREE treats served up daily at the Messenger Café. Stop by 
today.
http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline

[PHP] CURL - how to get URL of returned page?

2007-10-08 Thread Marianne Mason
Is there a way to get the URL of the page that is returned when using Curl? 
If I look at CURLINFO_EFFECTIVE_URL value from the return of curlget_info(), 
all I see is the URL I requested, not the one that is returned.

I am trying to write an URL checking script against a site that may return a 
page other than the one you requested without it being seen as a 302 
redirect status.  Even though my situation is somewhat out of the norm, I 
would imagine there are cases where people would want to see the URL with a 
302 status.

Am I missing something?  Does anyone have any suggestions for me?

Thanks,
Marianne 

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



RE: [PHP] Socket how to die if connection broken

2007-10-08 Thread Instruct ICC

> I dont get that error
> 
> Warning: socket_write() expects parameter 1 to be resource, null given in
> /path/script.php on line 34
> 
> but just the original error msg
> 
> Warning: socket_write(): unable to write to socket [32]: Broken pipe in

Multiple times still?
Or just the one time?

Use http://php.he.net/manual/en/function.socket-last-error.php
if (false === socket_write($sock, $buffer))
{
  $errorcode = socket_last_error();
  $errormsg = socket_strerror($errorcode);
  //socket_close($sock);//Doubt if this is needed if $sock isn't good
  exit("ERROR: [$errorcode] $errormsg");
}

_
Climb to the top of the charts!  Play Star Shuffle:  the word scramble 
challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct

RE: [PHP] Something you can do with AJAX + PHP as well

2007-10-08 Thread tedd

At 9:53 AM -0500 10/8/07, Jay Blanchard wrote:

[snip]
I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:
http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration
%20with%20AJAX.mpeg

Cool huh?
[/snip]

It is too bad that the video does not play.



Same here.

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] count vs mysql_num_rows

2007-10-08 Thread Jim Lucas

Kevin Murphy wrote:
I've got a little function that just checks to see if something is in a 
mysql db. There are several ways to do this and was curious as to the 
best way. The following are 2 (simplified) versions that work just fine. 
If these are the best ways, which of the following is better from a 
performance standpoint. And if there is a way that is better than one of 
these, I'd love to know what that is.


$query = "SELECT count(id) as count FROM wncci_intranet.iAdmin_users 
WHERE name = '$name' LIMIT 1";

$results = mysql_query($query);
$row = mysql_fetch_array($results);
$count = $row["count"];
return $count;

OR

$query = "SELECT id FROM wncci_intranet.iAdmin_users WHERE name = 
'$name' LIMIT 1";

$results = mysql_query($query);
$count = mysql_num_rows($results);
return $count;


Thanks.



Is this a joke?  You are using a LIMIT 1, so your count is always going to be 1.

But, if you didn't use the LIMIT 1 and really wanted to see how many the results would be found, 
then I would do it like this.


$SQL = "SELECT count(id)
FROMiAdmin_users
WHERE   name = '{$name}'";
$results = mysql_query($SQL) OR die('Mysql Error: '.mysql_error());

$count = 0;
if ( $results ) {
list($count) = mysql_fetch_row($results);
}
return $count;

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] count vs mysql_num_rows

2007-10-08 Thread Kevin Murphy


Is this a joke?  You are using a LIMIT 1, so your count is always  
going to be 1.


No, its not a joke. The answer is not going to always 1, its going to  
be 1 (the value exists in the DB at least once) or 0 (the value  
doesn't exist in the DB), that's what I am trying to test for. I  
don't need to know how many times something exists, just if it does.


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326

RE: [PHP] count vs mysql_num_rows

2007-10-08 Thread Jay Blanchard
[snip]
> Is this a joke?  You are using a LIMIT 1, so your count is always  
> going to be 1.

No, its not a joke. The answer is not going to always 1, its going to  
be 1 (the value exists in the DB at least once) or 0 (the value  
doesn't exist in the DB), that's what I am trying to test for. I  
don't need to know how many times something exists, just if it does.
[/snip]

If you just need to know if data exists use the query with limit 1 and
test to see if 1 === $result['count']. I agree with the poster about not
returning all of the rows, it is more efficient to do it this way.

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



[PHP] PHP loop control

2007-10-08 Thread David Peters
I'm looking for some ideas on the best way to perform the following.
1.  Give the user a webpage that allows him/her to start/stop a loop.
2.  Open a socket to a device.
3.  Issue commands to the device a read the results.
4.  Process the results.
5.  If the user selected 'Stop', exit the loop or go to #3 above.
6.  Close socket.

Is this type of loop possible in PHP?  What is the best way to do this type 
of loop control?  Are there examples out there?  It seems to me that 
starting an infinite loop would cause some problems trying to read the 
user's selection to stop the process.
I hope this makes sense.  If not, let me know. 

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



Re: [PHP] PHP loop control

2007-10-08 Thread Nathan Nobbe
On 10/8/07, David Peters <[EMAIL PROTECTED]> wrote:
>
> I'm looking for some ideas on the best way to perform the following.
> 1.  Give the user a webpage that allows him/her to start/stop a loop.
> 2.  Open a socket to a device.
> 3.  Issue commands to the device a read the results.
> 4.  Process the results.
> 5.  If the user selected 'Stop', exit the loop or go to #3 above.
> 6.  Close socket.
>
> Is this type of loop possible in PHP?  What is the best way to do this
> type
> of loop control?  Are there examples out there?  It seems to me that
> starting an infinite loop would cause some problems trying to read the
> user's selection to stop the process.
>

just make sure the code that handles user requests has access to the loop
control
variable.  that way a user will be able to terminate the loop.

-nathan


Re: [PHP] PHP loop control

2007-10-08 Thread Nathan Nobbe
actually, now that i think about it, the real problem is how to keep the
loop alive
after the script terminates.  hmm; that is a problem.

you could have a cli script run in the background.  the only way youll be
able to
get data to it from the scripts that send output to the browser is through
something
external to php.

you could use files, a database or something like shared memory.

-nathan


[PHP] php5 - possible bug discovered

2007-10-08 Thread David Restall - System Administrator
Hi,

I think I have discovered a bug in php5.  If I haven't, I've discovered
a bug in the documentation or a bug in my brain.

php -v :-

PHP 5.2.3 (cli) (built: Jun 26 2007 15:38:48) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

I've attached a code snippet for those that want to save it and try
running it and it's also pasted here :-


Text = $Text;
}

function Set($Text)
{
$this->Text = $Text;
}

function Display()
{
print $this->Text . "\n";
}
}   // End Class_1

class Class_2
{
private $Text;
private $C1;

function __construct($Text)
{
$this->Text = $Text;

$this->C1 = new Class_1('From David');
}

function Set_C1($Text)
{
$this->C1->Set($Text);
}

function Display()
{
print $this->Text . "\n";
$this->C1->Display();
}
}   // End Class_2

print "Below is T1\n";

$T1 = new Class_1('Hello');
$T1->Display();

print "Below is T2\n";
$T2 = new Class_2('World');
$T2->Display();

print "Copying T2\n";

$T3 = $T2;

print "T2 Copied, original value is :-\n";

$T2->Display();

print "Copy of T2 (T3) value is :- \n";

$T3->Display();

print "Changing T3\n";

$T3->Set_C1("This clears Dave");

print "T3 Change complete, new value is :-\n";

$T3->Display();

print "Below is T2 which shouldn't have changed !!! \n";

$T2->Display();

// var_dump($T1);

?>



The output it produces is :-

% php -e bug.php
Below is T1
Hello
Below is T2
World
>From David
Copying T2
T2 Copied, original value is :-
World
>From David
Copy of T2 (T3) value is :- 
World
>From David
Changing T3
T3 Change complete, new value is :-
World
This clears Dave
Below is T2 which shouldn't have changed !!! 
World
This clears Dave
%

Now I would expect that $T2 would not change when I changed $T3.
Reading the documentation :-



"... Note:  Not using the & operator causes a copy of the object to be
made. If you use $this in the class it will operate on the current
instance of the class. The assignment without & will copy the instance
(i.e. the object) and $this will operate on the copy, which is not
always what is desired. Usually you want to have a single instance to
work with, due to performance and memory consumption issues."

This effectively states that $T3 is a 'COPY' of $T2 and $T3 works on the
copy, not the master yet in the above snippet, the copy and the master
have both been changed.  Further documentation mentions that the copy
starts off as a reference and only becomes a copy when it is changed.
This doesn't seem to be happening.

I found this because in my actual application I was using :-
Master.class
...
$Clone = $this;

$Clone->Do_Something;


and later in master.class I did :-

$this->Do_Something_Else

and php barfed with :-

PHP Fatal error:  Call to a member function Function_Name() on a non-object 

I had deleted the missing object in $Clone but not in the master (this
was the whole idea of working on $Clone - I didn't want to delete the
object in the master !!).

I can't find anything similar in the bug database on php.net (but I may
be looking in the wrong place) and I can't believe that I'm the first
person to encounter this.

Can anybody explain if this is a bug or if I have misunderstood the
documentation ?

TTFN



D
php/general-2007-10-08.tx  php-general
++
| Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger  |
| Mob +44 (0) 7973 831245  Skype: dave.restall Radio: G4FCU  |
| email : [EMAIL PROTECTED] Web : Not Ready Yet :-(   |
++
| Good salesmen and good repairmen will never go hungry. |
| -- R. E. Schenk|
++



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

[PHP] Re: Something you can do with AJAX + PHP as well

2007-10-08 Thread Colin Guthrie
Jay Blanchard wrote:
> [snip]
> I saved it and it played in Winamp, but no audio
> [/snip]
> 
> So, is it worth going to all of the trouble to see? 
> 

In a word, "no".

I watched it fine in Firefox on Linux with mplayer pluing. It just
worked(tm) for me!

But overall I have to say I was somewhat disappointed. It was just your
standard Ajax stuff really, nothing PHP related at all and nothing that
isn't done slicker on Facebook and Flickr and other good Web 2.0 sites.

Sorry Mark but that's just the way it is. I'm sure it's useful in the
context but I wouldn't say it's rocket science or visually impressive.

Col

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



Re: [PHP] php5 - possible bug discovered

2007-10-08 Thread Robert Cummings
In PHP5 objects are no longer copied when assigned. Instead the object's
handle is assigned (similar to a reference but not quite). So the
behaviour is as expected.

Cheers,
Rob.


On Mon, 2007-10-08 at 21:42 +0100, David Restall - System Administrator
wrote:
> Hi,
> 
> I think I have discovered a bug in php5.  If I haven't, I've discovered
> a bug in the documentation or a bug in my brain.
> 
> php -v :-
> 
> PHP 5.2.3 (cli) (built: Jun 26 2007 15:38:48) 
> Copyright (c) 1997-2007 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
> 
> I've attached a code snippet for those that want to save it and try
> running it and it's also pasted here :-
> 
> 
>  
> class Class_1
> {
> private $Text;
> 
> function __construct($Text)
>   {
>   $this->Text = $Text;
>   }
> 
> function Set($Text)
>   {
>   $this->Text = $Text;
>   }
> 
> function Display()
>   {
>   print $this->Text . "\n";
>   }
> } // End Class_1
> 
> class Class_2
> {
> private $Text;
> private $C1;
> 
> function __construct($Text)
>   {
>   $this->Text = $Text;
> 
>   $this->C1 = new Class_1('From David');
>   }
> 
> function Set_C1($Text)
>   {
>   $this->C1->Set($Text);
>   }
> 
> function Display()
>   {
>   print $this->Text . "\n";
>   $this->C1->Display();
>   }
> } // End Class_2
> 
> print "Below is T1\n";
> 
> $T1 = new Class_1('Hello');
> $T1->Display();
> 
> print "Below is T2\n";
> $T2 = new Class_2('World');
> $T2->Display();
> 
> print "Copying T2\n";
> 
> $T3 = $T2;
> 
> print "T2 Copied, original value is :-\n";
> 
> $T2->Display();
> 
> print "Copy of T2 (T3) value is :- \n";
> 
> $T3->Display();
> 
> print "Changing T3\n";
> 
> $T3->Set_C1("This clears Dave");
> 
> print "T3 Change complete, new value is :-\n";
> 
> $T3->Display();
> 
> print "Below is T2 which shouldn't have changed !!! \n";
> 
> $T2->Display();
> 
> // var_dump($T1);
> 
> ?>
> 
> 
> 
> The output it produces is :-
> 
> % php -e bug.php
> Below is T1
> Hello
> Below is T2
> World
> >From David
> Copying T2
> T2 Copied, original value is :-
> World
> >From David
> Copy of T2 (T3) value is :- 
> World
> >From David
> Changing T3
> T3 Change complete, new value is :-
> World
> This clears Dave
> Below is T2 which shouldn't have changed !!! 
> World
> This clears Dave
> %
> 
> Now I would expect that $T2 would not change when I changed $T3.
> Reading the documentation :-
> 
> 
> 
> "... Note:  Not using the & operator causes a copy of the object to be
> made. If you use $this in the class it will operate on the current
> instance of the class. The assignment without & will copy the instance
> (i.e. the object) and $this will operate on the copy, which is not
> always what is desired. Usually you want to have a single instance to
> work with, due to performance and memory consumption issues."
> 
> This effectively states that $T3 is a 'COPY' of $T2 and $T3 works on the
> copy, not the master yet in the above snippet, the copy and the master
> have both been changed.  Further documentation mentions that the copy
> starts off as a reference and only becomes a copy when it is changed.
> This doesn't seem to be happening.
> 
> I found this because in my actual application I was using :-
> Master.class
> ...
> $Clone = $this;
> 
> $Clone->Do_Something;
> 
> 
> and later in master.class I did :-
> 
> $this->Do_Something_Else
> 
> and php barfed with :-
> 
> PHP Fatal error:  Call to a member function Function_Name() on a non-object 
> 
> I had deleted the missing object in $Clone but not in the master (this
> was the whole idea of working on $Clone - I didn't want to delete the
> object in the master !!).
> 
> I can't find anything similar in the bug database on php.net (but I may
> be looking in the wrong place) and I can't believe that I'm the first
> person to encounter this.
> 
> Can anybody explain if this is a bug or if I have misunderstood the
> documentation ?
> 
> TTFN
> 
> 
> 
> D
> php/general-2007-10-08.tx  php-general
> ++
> | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger  |
> | Mob +44 (0) 7973 831245  Skype: dave.restall Radio: G4FCU  |
> | email : [EMAIL PROTECTED] Web : Not Ready Yet :-(   
> |
> ++
> | Good salesmen and good repairmen will never go hungry. |
> | -- R. E. Schenk|
> ++
> 
> -- 
> PHP General

Re: [PHP] php5 - possible bug discovered

2007-10-08 Thread Stut

David Restall - System Administrator wrote:

I think I have discovered a bug in php5.  If I haven't, I've discovered
a bug in the documentation or a bug in my brain.


Start here: http://php.net/language.oop5.cloning

-Stut

--
http://stut.net/

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



[PHP] How to format CLI tabular data?

2007-10-08 Thread Daevid Vincent
I write many CLI scripts in PHP to clean up DB records, etc via crontab
scripts. Often though, I implement command line switches to 'debug' or see
various data as a precaution before actually purging.

Perl has some neat tools built in to format tabular data:
http://www.usenix.org/publications/perl/perl08.html

Does PHP have any tools like this? I'd prefer not to pull in some PEAR
package or other bloat, but I'll take what I can get if it actually works
well. I was hoping there are some tips/tricks to show simple tabular data:

i.e.:

# foo.php --showgroups

==
  Groups
==
Name: Expires: Date:
   ---
groupA3 hours   2007-10-08
groupBeta10 hours   2007-11-10
groupC1 week2007-12-31


notice basic things like alignment, 
length of data (as in 'tabs' won't work), etc.

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



Re: [PHP] count vs mysql_num_rows

2007-10-08 Thread tedd

At 12:47 PM -0700 10/8/07, Kevin Murphy wrote:
Is this a joke?  You are using a LIMIT 1, so your count is always 
going to be 1.


No, its not a joke. The answer is not going to always 1, its going 
to be 1 (the value exists in the DB at least once) or 0 (the value 
doesn't exist in the DB), that's what I am trying to test for. I 
don't need to know how many times something exists, just if it does.


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326


Kevin:

Considering what you want to do, you might want to investigate having 
mysql do it for you, see here:




Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] MySQL and SESSIONs

2007-10-08 Thread Philip Thompson
On 10/5/07, Stut <[EMAIL PROTECTED]> wrote:
>
> Vo, Lance wrote:
> > What's good for multiple webservers? thanks
>
> * DO NOT USE PERSISTANT CONNECTIONS
>
> * Minimise the amount of time you keep a database connection open during
> a request. Good logic/presentation separation helps a lot here.
>
> * Cache the crap out of everything - don't hit the DB unless you really
> need to.
>
> -Stut
>
> --
> http://stut.net/
>
> > -Original Message-
> > From: Stut [mailto:[EMAIL PROTECTED]
> > Sent: Friday, October 05, 2007 4:31 PM
> > To: Stefano Esposito
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] MySQL and SESSIONs
> >
> >
> > Stefano Esposito wrote:
> >> is it somehow possible to store the connection reference obtained from
> mysql_connect() (note the absence of the "i") in a $_SESSION element?
> >
> > No. Why would you want to? You'd end up holding on to a database
> > connection even when nothing is using it. If you want to optimise things
> > look at http://php.net/mysql_pconnect but bear in mind that this starts
> > to suck if you scale up to multiple web servers.
> >
> > -Stut



Hi. This may not be best practice, but I think it's great to use -
especially since I can use multiple functions with the same database
connection w/o having to send the db link/resource. Store the connection in
the GLOBALS variable - this way, it's accessible by each function AND is
destroyed when the script completes (e.g., when the processing is complete
for the current page).

[code]
connect.php:
$_GLOBALS['dbLink'] = mysql_connect (DATABASE, USER, PASS);
...

functions.php:
function someFunction () {

$result = mysql_query ($query, $_GLOBALS['dbLink']);

// Don't close the connection
}

somePage.php:
$something = someFunction();
...
mysql_close ($_GLOBALS['dbLink']); // End of page - close connection
[/code]

That's the general gist of it. BTW, if this is bad practice or there is
something more efficient, please let me know. =P

~Philip


Re: [PHP] Sending lots of emails - 2 choices - choose the best one

2007-10-08 Thread Philip Thompson
On 10/7/07, Stut <[EMAIL PROTECTED]> wrote:
>
> Martin Zvarík wrote:
> > Hello--
> >I want to send email to 100+ recipients. Two choices I thought of:
> >
> > 1) once call mail() and use BCC, but the negative of this method is that
> > every recipient in BCC has header "To" same (so I used to put my email
> > in here - not email of one of the recipients).
> >
> > 2) several calls to mail() function with each recipient's emal
>
> Why are you sending mail to 100+ recipients? Is it something you do
> often? Is it always the same recipients? When are you sending them?
>
> If it's a mailing list use mailing list software as Daevid suggested -
> it's what it's for!
>
> I would recommend avoiding the use of BCC from PHP.
>
> -Stut



Why avoid Bcc from PHP?

~Philip


Re: [PHP] MySQL and SESSIONs

2007-10-08 Thread mike
On 10/8/07, Philip Thompson <[EMAIL PROTECTED]> wrote:
> Hi. This may not be best practice, but I think it's great to use -
> especially since I can use multiple functions with the same database
> connection w/o having to send the db link/resource. Store the connection in
> the GLOBALS variable - this way, it's accessible by each function AND is
> destroyed when the script completes (e.g., when the processing is complete
> for the current page).
>
> [code]
> connect.php:
> $_GLOBALS['dbLink'] = mysql_connect (DATABASE, USER, PASS);
> ...
>
> functions.php:
> function someFunction () {
>
>$result = mysql_query ($query, $_GLOBALS['dbLink']);
>
>// Don't close the connection
> }
>
> somePage.php:
> $something = someFunction();
> ...
> mysql_close ($_GLOBALS['dbLink']); // End of page - close connection
> [/code]
>
> That's the general gist of it. BTW, if this is bad practice or there is
> something more efficient, please let me know. =P
>
> ~Philip
>

I do not use persistent connections, nor store resources in session
variables. I do the same thing with a global variable.

However, I don't automatically open a db link. I only open it if a db
function is requested. I check for the presence of $GLOBALS['dbh'], if
it exists, then I have an existing connection. If not, then it will
make one.

It seems to perform extremely well. It also guarantees only one
connection per page *(per datasource, I just added in support for
multiple) *if needed*, and is very little PHP code. All the DB
routines I need are under 75 lines of code (indented/nested and even a
small error handling function) - there are no other routines I need. I
don't even remember the specific mysqli_* functions anymore, because I
never call them directly.

I haven't really had to change it besides for adding the multiple
datasources in years, and it was seamless to change from mysql to
mysqli, etc.

I did run in to a performance issue though, I was having ~ 60 clients
waiting for data on my mysql server all the time. Turns out it was
100% the database - a few key tables were being slammed with reads and
writes. Changed them to InnoDB and now I can do a "show processlist"
and usually don't see any active threads - each page loads, connects
to the database if needed (which all pages do) and does all the work
so quickly I can't even catch it with my own eyes. It's amazing. At
one point it was doing over 1,000 queries per second over a 60 day
average - and it's just a dual-core processor with 4 gig of ram and a
single SATA disk.

Simplicity is always best!

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



Re: [PHP] How to format CLI tabular data?

2007-10-08 Thread Robert Cummings
On Mon, 2007-10-08 at 15:59 -0700, Daevid Vincent wrote:
> I write many CLI scripts in PHP to clean up DB records, etc via crontab
> scripts. Often though, I implement command line switches to 'debug' or see
> various data as a precaution before actually purging.
> 
> Perl has some neat tools built in to format tabular data:
> http://www.usenix.org/publications/perl/perl08.html
> 
> Does PHP have any tools like this? I'd prefer not to pull in some PEAR
> package or other bloat, but I'll take what I can get if it actually works
> well. I was hoping there are some tips/tricks to show simple tabular data:
> 
> i.e.:
> 
> # foo.php --showgroups
> 
> ==
>   Groups
> ==
> Name: Expires: Date:
>    ---
> groupA3 hours   2007-10-08
> groupBeta10 hours   2007-11-10
> groupC1 week2007-12-31
> 
> 
> notice basic things like alignment, 
> length of data (as in 'tabs' won't work), etc.

Looks like something you could whip up in half an hour.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] How to format CLI tabular data?

2007-10-08 Thread Larry Garfield
Look into sprintf().  I believe it has whitespace formatting codes that are 
wonderfully suited to this case.  (They're derived from C, where the printf() 
routine is used quite frequently for that sort of screen output.)

On Monday 08 October 2007, Robert Cummings wrote:
> On Mon, 2007-10-08 at 15:59 -0700, Daevid Vincent wrote:
> > I write many CLI scripts in PHP to clean up DB records, etc via crontab
> > scripts. Often though, I implement command line switches to 'debug' or
> > see various data as a precaution before actually purging.
> >
> > Perl has some neat tools built in to format tabular data:
> > http://www.usenix.org/publications/perl/perl08.html
> >
> > Does PHP have any tools like this? I'd prefer not to pull in some PEAR
> > package or other bloat, but I'll take what I can get if it actually works
> > well. I was hoping there are some tips/tricks to show simple tabular
> > data:
> >
> > i.e.:
> >
> > # foo.php --showgroups
> >
> > ==
> >   Groups
> > ==
> > Name: Expires: Date:
> >    ---
> > groupA3 hours   2007-10-08
> > groupBeta10 hours   2007-11-10
> > groupC1 week2007-12-31
> >
> >
> > notice basic things like alignment,
> > length of data (as in 'tabs' won't work), etc.
>
> Looks like something you could whip up in half an hour.
>
> Cheers,
> Rob.
> --
> ...
> SwarmBuy.com - http://www.swarmbuy.com
>
> Leveraging the buying power of the masses!
> ...


-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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