php-general Digest 16 Nov 2005 10:25:18 -0000 Issue 3797

Topics (messages 225878 through 225906):

Re: Is echo tag reasonably portable?
        225878 by: Richard Davey
        225879 by: Robin Vickery
        225880 by: Richard Davey
        225881 by: Robin Vickery
        225895 by: Curt Zirzow

include/include_once php_check_syntax() / E_PARSE errors
        225882 by: Thiago Silva
        225885 by: Curt Zirzow

Re: PHP Framework
        225883 by: Aaron Greenspan

unsubscribing
        225884 by: wayne
        225886 by: Curt Zirzow

Re: Catch warnings
        225887 by: Curt Zirzow

Re: Regex for Amateur Radio Callsigns
        225888 by: Curt Zirzow
        225890 by: Leonard Burton
        225897 by: Curt Zirzow
        225900 by: Leonard Burton
        225903 by: Curt Zirzow

Re: Shared Memory Problem
        225889 by: Curt Zirzow
        225905 by: Yaswanth Narvaneni
        225906 by: Yaswanth Narvaneni

Re: wierd error
        225891 by: Curt Zirzow

Re: Validating Email addrs
        225892 by: Curt Zirzow
        225904 by: George Pitcher

random row
        225893 by: John Taylor-Johnston
        225894 by: Jasper Bryant-Greene
        225898 by: Curt Zirzow

Set Timezone to localtime in php.ini
        225896 by: The Doctor

Re: [EMAIL PROTECTED]
        225899 by: Curt Zirzow

Query about gzinflate
        225901 by: kumar kumar
        225902 by: Curt Zirzow

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hi Robin,

Tuesday, November 15, 2005, 7:53:55 PM, you wrote:

> I did quote the note concerning them in its entirety. If I had
> simply quoted the manual as saying "be sure not to use short tags"
> then I could see your point regarding lack of context. But I didn't.

Not in the message I was replying to, hence my comments. Although
having re-scanned the thread, it was quoted further back by someone
else. Personally I find there is a vast difference in meaning between
"don't use short-tags" and "don't use short-tags for distributed
applications".

> Firstly, I didn't actually suggest they were disabled. I suggested
> that they should be off by default. If they're needed then it's
> simple to turn them on, but it would discourage new developers from
> using a construct which is not compatible with xml and xhtml.

Agreed. Although, if they needed that construct, don't you think
they'd realise the implications rather quickly? (most likely at the
point at which everything goes tits up?! ;)

Cheers,

Rich
-- 
Zend Certified Engineer
PHP Development Services
http://www.corephp.co.uk

--- End Message ---
--- Begin Message ---
On 11/15/05, Greg Donald <[EMAIL PROTECTED]> wrote:
> On Tue, 15 Nov 2005, Jim Moseby wrote:
>
> >> for file in *.php; do
> >> cp $file $file.tmp
> >> sed -e "s/<?$/<?php/g" $file.tmp >$file
> >> rm $file.tmp
> >> done
> >
> > I maintain: "Better to save the grief and do it right to start with, no?"
>
> Maybe at some point I too will be lucky enough to only work on code that
> I authored.
>
> for file in *.php; do
> cp $file $file.tmp
> php -r 'echo preg_replace("/<\?php=\s*/i","<?php echo
> ",preg_replace("/<\?(?!php)/i","<?php",file_get_contents($argv[1])));'
> $file.tmp >$file
> rm $file.tmp
> done
>

$stmt = $mysqli->prepare("SELECT foo FROM bar WHERE baz<?");

oops...

  -robin

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

Tuesday, November 15, 2005, 8:01:01 PM, you wrote:

> Still best practice is to use long tags. Suppose you write a
> closed-app for a client who makes a business decision to move it to
> a hosted server that does not allow short tags... The down side is,
> the app will break. The up side is, the client will probably call
> you to fix it, and pay you your standard rate to do so, unless he is
> bright enough to realize it was YOUR fault it broke.

To be honest, if a client upped and move an application I'd built to
an entirely different host, without consulting me prior to the move,
I'd place the blame ball firmly in their court.

I've never signed a contract yet that said "this code will work
anywhere you dump it", and I never will.

However, I understand what you're saying, and I agree with it
completely. I use long tags for all full app developments, and
short-tags for all prototypes.

My only point is that when two options are identical in nature, there
is no "best preference", only that which is the best for you, and your
immediate needs.

If your host doesn't support them, that's a pretty immediate need. If
your client likes to up and move stuff around without telling you,
that's quite a need too. If you had the luxury of building the entire
site from scratch, then it's your issue. However if your client wants
maintenance on a 3 year old app, spread across hundreds of files, with
thousands of lines of inter-mingled short-tagged code -- well, that's
a slightly different concern, and "best practises" don't always apply.

It ain't never black or white!

Cheers,

Rich
-- 
Zend Certified Engineer
PHP Development Services
http://www.corephp.co.uk

--- End Message ---
--- Begin Message ---
On 11/15/05, Greg Donald <[EMAIL PROTECTED]> wrote:
> On Tue, 15 Nov 2005, Jim Moseby wrote:
>
> >> for file in *.php; do
> >> cp $file $file.tmp
> >> sed -e "s/<?$/<?php/g" $file.tmp >$file
> >> rm $file.tmp
> >> done
> >
> > I maintain: "Better to save the grief and do it right to start with, no?"
>
> Maybe at some point I too will be lucky enough to only work on code that
> I authored.
>
> for file in *.php; do
> cp $file $file.tmp
> php -r 'echo preg_replace("/<\?php=\s*/i","<?php echo
> ",preg_replace("/<\?(?!php)/i","<?php",file_get_contents($argv[1])));'
> $file.tmp >$file
> rm $file.tmp
> done

I'd be inclined to do it with the tokenizer functions with something
like this (untested):

<?php

$source = file_get_contents($argv[1]);
$token = token_get_all($source);

foreach ($token as $t) {
  if (is_string($t)) {
    print $t;
    continue;
  }

  switch ($t[0]) {
  case T_OPEN_TAG_WITH_ECHO:
    print '<?php echo ';
    break;
  case T_OPEN_TAG:
    print '<?php ';
    break;
  case T_CLOSE_TAG:
    print ' ?>';
    break;
  default:
    print $t[1];
  }
}

?>

--- End Message ---
--- Begin Message ---
On Wed, Nov 16, 2005 at 01:27:12AM +0200, Robin Vickery wrote:
> On 11/15/05, Greg Donald <[EMAIL PROTECTED]> wrote:
> > On Tue, 15 Nov 2005, Jim Moseby wrote:
> >
> > >> for file in *.php; do
> > >> cp $file $file.tmp
> > >> sed -e "s/<?$/<?php/g" $file.tmp >$file
> > >> rm $file.tmp
> > >> done
> > ...
> >
> > for file in *.php; do
> > cp $file $file.tmp
> > php -r 'echo preg_replace("/<\?php=\s*/i","<?php echo
> > ",preg_replace("/<\?(?!php)/i","<?php",file_get_contents($argv[1])));'
> > $file.tmp >$file
> > rm $file.tmp
> > done
> ...
> $token = token_get_all($source);
> 
> foreach ($token as $t) {
>   if (is_string($t)) {
>     print $t;
>     continue;
>   }
> 
>   switch ($t[0]) {
>   case T_OPEN_TAG_WITH_ECHO:
>     print '<?php echo ';
>     break;
> ...

This is a good finale for this thread!! 

Curt.
-- 

--- End Message ---
--- Begin Message ---
Hello all,
Recently I had some problems with include/include_once.

This is the scenario:

My application uses only classes loaded through a centered __autoload()
function (no "require/include" anywere in the scripts, but in __autoload()
itself).

Now, diverse libraries use diverse extensions. For instance, Smarty class is
declared in Smarty.class.php. And many of my classes uses a simple .php
extension.

So, __autload has to *try* include_once's. Something like that:

function __autoload($className) {
 include_once("${className}.php");
 if(class_exists($className, false)) return;

 include_once("${className}.class.php");
 if(class_exists($className, false)) return;

 die("class not found: $className");
}

Then, loading Smarty would generate a warning message because the first
include_once tries to load Smarty.php (wich doesn't exists). 

Since those warning messages are common, naturaly I use @include_once
statements. 

But, as soon as I'm writing scripts, and one of the classes included
generates an E_PARSE error, I get a blank result in my browser, because @
supress the messages. 

Having explained the problem, I would like to know:

1: Is there an elegant way to resolve this?

2: What happened to php_check_syntax?

3: What was the final word about include() behavior regarding E_PARSE error?
Reading and searching the bug database, I read some posts that seemed to
indicate that include() should *not* halt on E_PARSE errors, but then, php5
does halt the execution. 

4: Halting the execution on E_PARSE error generated through an include() is
a coherent/expected behavior? (it doesn't seem to me). 

5: Why? (depending on the answer to that question, I'll head to
bugs.php.net).

Thanks,
Thiago

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 10:48:56PM +0000, Thiago Silva wrote:
> ...
> So, __autload has to *try* include_once's. Something like that:
> 
> function __autoload($className) {
>  include_once("${className}.php");
>  if(class_exists($className, false)) return;
> 
>  include_once("${className}.class.php");
>  if(class_exists($className, false)) return;
> 
>  die("class not found: $className");
> }
> 
> Then, loading Smarty would generate a warning message because the first
> include_once tries to load Smarty.php (wich doesn't exists). 
>
> ...
> Having explained the problem, I would like to know:
> 
> 1: Is there an elegant way to resolve this?

For third party classes I usually extend it myself with my own
naming convention, so like with smarty I would create a class like:

Template.php:
<?php
require_once('path/where/smartyis.php');

class Template extends Smarty {
}

> 
> 2: What happened to php_check_syntax?

It was removed for technical reasons. one option is to use:
  http://php.net/runkit

> 3: What was the final word about include() behavior regarding E_PARSE error?
> Reading and searching the bug database, I read some posts that seemed to
> indicate that include() should *not* halt on E_PARSE errors, but then, php5
> does halt the execution. 
> 
> 4: Halting the execution on E_PARSE error generated through an include() is
> a coherent/expected behavior? (it doesn't seem to me). 
> 
> 5: Why? (depending on the answer to that question, I'll head to
> bugs.php.net).

This does seem odd.
  http://bugs.php.net/bug.php?id=31736

It seems it was fixed then, although 5.1 seems to be broke for me.
5.0 is fine.


Curt.
-- 

--- End Message ---
--- Begin Message ---
Yonatan,

And since I'm the Lampshade guy, I'll throw Lampshade out there, as well:

http://www.thinkcomputer.com/software/lampshade/index.html

Unlike a lot of frameworks, Lampshade is entirely procedural, and it's designed specifically for use with MySQL. I suppose that makes it less flexible than some people would want, but if it fits your application specs, then it's very fast and straightforward.

In general, it's been around since 2002 (no plans to go away next year), it's in use at Harvard and at very large companies, and at very small ones, too, and there's a whole lot of documentation, in both HTML and PDF format. I also happen to think that as far as programming frameworks go, it's pretty easy to learn. The Lampshade Starter Kit, which you can download alongside the core files, gives you an example application that you can work with and modify.

Good luck with your search!

Aaron

Aaron Greenspan
President & CEO
Think Computer Corporation

http://www.thinkcomputer.com

--- End Message ---
--- Begin Message ---
I tried to unsubscribe on several occasion without
success. I followed the instruction at the bottom 
of the email. Can someone take me off the list.
Thank You.

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 09:33:42PM -0500, wayne wrote:
> I tried to unsubscribe on several occasion without
> success. I followed the instruction at the bottom 
> of the email. Can someone take me off the list.
> Thank You.

you can always send an email to:

  [EMAIL PROTECTED]


Curt.
-- 

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 04:39:05PM -0300, Mariano Guadagnini wrote:
> Hi, i�m writting a php program that parses and saves some xml files on a 
> server. The problem is that i want to catch warnings so as to be able to 
> store them in a variable, but not to be put directly on client�s 
> browser. I got the following code, but i cannot get it working:
> //--------------------------------------------------------
> $old_track = ini_set('track_errors', '1');
> 
> if ([EMAIL PROTECTED]()) {
> echo $php_errormsg, "\n";
> }
> 
> ini_set('track_errors', $old_track);
> //--------------------------------------------------------
> When i execute the cgi, the $php_errormsg variable is always empty, even 
> when there are errors.
> 
> Any ideas?

I'd probably scratch that approach and use set_error_handler()
instead.  You could even get fancy and create a class that uses
it so your code could be something like:

<?php
  phpErrorHandler::start();
  // some code that causes errors... 
  phpErrorHander::stop();
?>

Although i see this more as a developement tool than production
solution.


Curt
-- 

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 03:47:21PM -0500, Leonard Burton wrote:
> 
> Does anyone know of a regex to work for Amateur Radio Callsigns that
> will work with any from across the world?

What does a amateur radio callsign look like? And in what context
are you trying to parse this callsign?


Curt.
-- 

--- End Message ---
--- Begin Message ---
HI Curt,

Thanks for the reply,

> What does a amateur radio callsign look like? And in what context
> are you trying to parse this callsign?

Basically here is the regex I used (I am not the best with regexes):

$pattern = "/^[0-9]?[A-Z]{1,2}[0-9][A-Z]{1,3}/";

Here are how they look
W1W
W1AW
WA1W
AD4HZ
N9URK
WB6NOA
4N1UBG

I guess this would be better?

$pattern  = "/^";
$pattern .= "([0-9][A-Z][0-9][A-Z]{3})|"; //4N1UBG
$pattern .= "([A-Z][0-9][A-Z]{1,3})|";    //N9URK, W1AW, W1W
$pattern .= "([A-Z]{2}[0-9][A-Z]{1,3})"; //WB6NOA, AD4HZ, WA1W
$pattern .= "/";

I am still trying to master regexes.  Is there a better way to do this?

THanks,



--
Leonard Burton, N9URK
[EMAIL PROTECTED]


"The prolonged evacuation would have dramatically affected the
survivability of the occupants."

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 10:39:19PM -0500, Leonard Burton wrote:
> HI Curt,
> 
> Thanks for the reply,
> 
> > What does a amateur radio callsign look like? And in what context
> > are you trying to parse this callsign?
> 
> Basically here is the regex I used (I am not the best with regexes):
> 
> $pattern = "/^[0-9]?[A-Z]{1,2}[0-9][A-Z]{1,3}/";
> 
> Here are how they look
> W1W
> W1AW
> WA1W
> AD4HZ
> N9URK
> WB6NOA
> 4N1UBG

Ok, so i can conclude so far we have alpha numeric chars minimum of
3 chars up to 6, this would make a regex:

  /[A-Z0-9]{3,6}/

I would assume however that the first char (or two) probably
signifies the location of the callsign and based on the location a
certain pattern is needed.

> 
> I guess this would be better?
> 
> $pattern  = "/^";
> $pattern .= "([0-9][A-Z][0-9][A-Z]{3})|"; //4N1UBG
> $pattern .= "([A-Z][0-9][A-Z]{1,3})|";    //N9URK, W1AW, W1W
> $pattern .= "([A-Z]{2}[0-9][A-Z]{1,3})"; //WB6NOA, AD4HZ, WA1W
> $pattern .= "/";
> 
> I am still trying to master regexes.  Is there a better way to do this?

For one trying to master regex's you seem to have a good grasp on
it. If this pattern works according to the specs of a callsign, it
should work fine. You could try to combine the regex into one
statment (without the | condition) but that would make the regex
rather ugly.

One thing i would suggest, although probably a minor issue
considering how long the string is,  is to make sure you put the
most likely match in your first pattern to match.

 
Curt.
--

--- End Message ---
--- Begin Message ---
HI Curt,
> > W1W
> > W1AW
> > WA1W
> > AD4HZ
> > N9URK
> > WB6NOA
> > 4N1UBG
> Ok, so i can conclude so far we have alpha numeric chars minimum of
> 3 chars up to 6, this would make a regex:
>   /[A-Z0-9]{3,6}/

The only problem with this is that it would take "444" which is not a
valid call.
> > $pattern  = "/^";
> > $pattern .= "([0-9][A-Z][0-9][A-Z]{3})|"; //4N1UBG
> > $pattern .= "([A-Z][0-9][A-Z]{1,3})|";    //N9URK, W1AW, W1W
> > $pattern .= "([A-Z]{2}[0-9][A-Z]{1,3})"; //WB6NOA, AD4HZ, WA1W
> > $pattern .= "/";
> >
> > I am still trying to master regexes.  Is there a better way to do this?
>
> For one trying to master regex's you seem to have a good grasp on
> it.

Thanks for the support.  I think I can do regex's pretty well but I do
not have a mastery of them yet.

> If this pattern works according to the specs of a callsign, it
> should work fine. You could try to combine the regex into one
> statment (without the | condition) but that would make the regex
> rather ugly.

I am looking for a regex that I can use for both preg_split and
preg_match.  I have not yet really learned how to do preg_splits yet. 
I am still trying to figure out what in the world to do.   I have done
some preg_splits and I know enought to know that if you have more than
one set of () that will return on an expression then it will royally
mess things up.

> One thing i would suggest, although probably a minor issue
> considering how long the string is,  is to make sure you put the
> most likely match in your first pattern to match.

Actually that is a good suggestion.  I can see how it would make
things more efficent.  Should you order the whole expression in terms
of how likely it is to get a result?
(i.e. "/^(most)|(frequent)|(least)/")

Thanks for the help!

--
Leonard Burton, N9URK
[EMAIL PROTECTED]


"The prolonged evacuation would have dramatically affected the
survivability of the occupants."

--- End Message ---
--- Begin Message ---
On Wed, Nov 16, 2005 at 12:25:22AM -0500, Leonard Burton wrote:
> HI Curt,
> > > W1W
> > > W1AW
> > > WA1W
> > > AD4HZ
> > > N9URK
> > > WB6NOA
> > > 4N1UBG
> > Ok, so i can conclude so far we have alpha numeric chars minimum of
> > 3 chars up to 6, this would make a regex:
> >   /[A-Z0-9]{3,6}/
> 
> The only problem with this is that it would take "444" which is not a
> valid call.
> > > $pattern  = "/^";
> > > $pattern .= "([0-9][A-Z][0-9][A-Z]{3})|"; //4N1UBG
> > > $pattern .= "([A-Z][0-9][A-Z]{1,3})|";    //N9URK, W1AW, W1W
> > > $pattern .= "([A-Z]{2}[0-9][A-Z]{1,3})"; //WB6NOA, AD4HZ, WA1W
> > > $pattern .= "/";
> > >
> 
> > If this pattern works according to the specs of a callsign, it
> > should work fine. You could try to combine the regex into one
> > statment (without the | condition) but that would make the regex
> > rather ugly.
> 
> I am looking for a regex that I can use for both preg_split and
> preg_match.  I have not yet really learned how to do preg_splits yet. 
> I am still trying to figure out what in the world to do.   I have done
> some preg_splits and I know enought to know that if you have more than
> one set of () that will return on an expression then it will royally
> mess things up.

I guess the difference between a _match a _split is that a _match
is what you are looking for a _split is what is usually ignored
because you want to seperate the data based on the regex.  if you
use _split and want to know what the value was, then use the
PREG_SPLIT_DELIM_CAPTURE option for it, the array returned will
include the match that made the split to occur.

> 
> > One thing i would suggest, although probably a minor issue
> > considering how long the string is,  is to make sure you put the
> > most likely match in your first pattern to match.
> 
> Actually that is a good suggestion.  I can see how it would make
> things more efficent.  Should you order the whole expression in terms
> of how likely it is to get a result?
> (i.e. "/^(most)|(frequent)|(least)/")

yeah, i wouldn't consider myself that much of an expert on it but
from my understanding on matching the sooner the match the better.
That is usually why the anchor ^ is used in most expression, if
pcre knows it is a start of the line it doesn't have to do any
fuzzy matching, it knows exactly where to start.

What kind of context are you trying to match?

A paragraph that mentions a callsign:
  You can contact me at 4N1UBG, blah blah

or some sort of formated data:

  4N1UBG, me
  N9URK, someone
  ...


Curt.
-- 

--- End Message ---
--- Begin Message ---
On Wed, Nov 16, 2005 at 03:33:22AM +0530, Yaswanth Narvaneni wrote:
> Hi!
> 
> I have a server written in C++ and my webpages are in PHP. The PHP has
> to communicate with the server using shared memory. This was working
> fine on the server running FC-1 with php-4.3.8. We recently migrated
> to CentOS 4.1 (Equivalent to RHEL 4.1) running php-4.3.9. The error it
> displays is as follows:
> 
> shmop_open(): unable to attach or create shared memory segment in
> /var/www/html/sharedmem.php on line 2
> 
> The server opens the shm in 666 (originally was 644) even then it was
> not working. I can see the shared mem open using 'ipcs' command.
> 
> ...
> $shm_id = shmop_open($shm_key, "a",0,0) or die("FATAL ERROR:: Unable
> to Access Shared Memory");

You might want to try to open it within the same mode that the
server created it in:

1)
  $shm_id = shmop_open($shm_key, "a",0666,0);

2)
  are you 100% sure the key is valid? the error message you are
  getting seems to point in this direction since the shmop_open is
  failing on the C call to shmget(), wich usually fails when either
  you dont have enough memory to create it (which you arn't doing),
  some other creation problems, or that the key supplied wasn't
  found.


Curt.
--

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

These are my open shared memories in the server output of ipcs command.

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 18645001   gOLeM     600        393216     2          dest
0x0000162e 18808842   root      666        30         1

The last one the the sharedmem the php will be using. the key is 5678
and as you said I
have modified my code to

$shm_id = shmop_open(intval($shm_key), "a",666,0) or die("FATAL
ERROR:: $php_errormsg");

U obtain the shm_key from a file. The key I am using is 5678 and it is
getting that value from the file. I even hardcoded the value, but the
error is not getting solved.

Is this a proble with any of the server configs? Coz we have
downloaded an example C file and this is also not working with the
PHP. Where as if the server and client both written in C are able to
communicate using the shared memory. Any clue any one??

Ok...just a crazy query...does it have anything to do with
Notice: import_request_variables(): No prefix specified - possible
security hazard in

which occurs due to register_globals set to Off??

On 11/16/05, Curt Zirzow <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 16, 2005 at 03:33:22AM +0530, Yaswanth Narvaneni wrote:
> > Hi!
> >
> > I have a server written in C++ and my webpages are in PHP. The PHP has
> > to communicate with the server using shared memory. This was working
> > fine on the server running FC-1 with php-4.3.8. We recently migrated
> > to CentOS 4.1 (Equivalent to RHEL 4.1) running php-4.3.9. The error it
> > displays is as follows:
> >
> > shmop_open(): unable to attach or create shared memory segment in
> > /var/www/html/sharedmem.php on line 2
> >
> > The server opens the shm in 666 (originally was 644) even then it was
> > not working. I can see the shared mem open using 'ipcs' command.
> >
> > ...
> > $shm_id = shmop_open($shm_key, "a",0,0) or die("FATAL ERROR:: Unable
> > to Access Shared Memory");
>
> You might want to try to open it within the same mode that the
> server created it in:
>
> 1)
>   $shm_id = shmop_open($shm_key, "a",0666,0);
>
> 2)
>   are you 100% sure the key is valid? the error message you are
>   getting seems to point in this direction since the shmop_open is
>   failing on the C call to shmget(), wich usually fails when either
>   you dont have enough memory to create it (which you arn't doing),
>   some other creation problems, or that the key supplied wasn't
>   found.
>
>
> Curt.
> --
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
"In theory there is no difference between theory and practice.
In practice there is." -- Fortune Cookie

--- End Message ---
--- Begin Message ---
Hi!

There is a strange problem now. This is the error message my php file gives.
"kernel not configured for shared memory kernel not configured for
semaphores kernel not configured for message queues"

The source is as follows:
<?php

$shm_id = shmop_open(5678, "a", 0, 0);
if (!$shm_id) {
   echo "Couldn't create shared memory segment\n : $php_errormsg";
}

print "<br>";
print system("ipcs");

?>

when I logged into my machine as user apache and tried ipcs command it
was working fine (I changed the shell of apache from /sbin/nologin to
/bin/bash)

Any clue??

Regards,
Yaswanth


On 11/16/05, Yaswanth Narvaneni <[EMAIL PROTECTED]> wrote:
> Hi Curt,
>
> These are my open shared memories in the server output of ipcs command.
>
> ------ Shared Memory Segments --------
> key        shmid      owner      perms      bytes      nattch     status
> 0x00000000 18645001   gOLeM     600        393216     2          dest
> 0x0000162e 18808842   root      666        30         1
>
> The last one the the sharedmem the php will be using. the key is 5678
> and as you said I
> have modified my code to
>
> $shm_id = shmop_open(intval($shm_key), "a",666,0) or die("FATAL
> ERROR:: $php_errormsg");
>
> U obtain the shm_key from a file. The key I am using is 5678 and it is
> getting that value from the file. I even hardcoded the value, but the
> error is not getting solved.
>
> Is this a proble with any of the server configs? Coz we have
> downloaded an example C file and this is also not working with the
> PHP. Where as if the server and client both written in C are able to
> communicate using the shared memory. Any clue any one??
>
> Ok...just a crazy query...does it have anything to do with
> Notice: import_request_variables(): No prefix specified - possible
> security hazard in
>
> which occurs due to register_globals set to Off??
>
> On 11/16/05, Curt Zirzow <[EMAIL PROTECTED]> wrote:
> > On Wed, Nov 16, 2005 at 03:33:22AM +0530, Yaswanth Narvaneni wrote:
> > > Hi!
> > >
> > > I have a server written in C++ and my webpages are in PHP. The PHP has
> > > to communicate with the server using shared memory. This was working
> > > fine on the server running FC-1 with php-4.3.8. We recently migrated
> > > to CentOS 4.1 (Equivalent to RHEL 4.1) running php-4.3.9. The error it
> > > displays is as follows:
> > >
> > > shmop_open(): unable to attach or create shared memory segment in
> > > /var/www/html/sharedmem.php on line 2
> > >
> > > The server opens the shm in 666 (originally was 644) even then it was
> > > not working. I can see the shared mem open using 'ipcs' command.
> > >
> > > ...
> > > $shm_id = shmop_open($shm_key, "a",0,0) or die("FATAL ERROR:: Unable
> > > to Access Shared Memory");
> >
> > You might want to try to open it within the same mode that the
> > server created it in:
> >
> > 1)
> >   $shm_id = shmop_open($shm_key, "a",0666,0);
> >
> > 2)
> >   are you 100% sure the key is valid? the error message you are
> >   getting seems to point in this direction since the shmop_open is
> >   failing on the C call to shmget(), wich usually fails when either
> >   you dont have enough memory to create it (which you arn't doing),
> >   some other creation problems, or that the key supplied wasn't
> >   found.
> >
> >
> > Curt.
> > --
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> "In theory there is no difference between theory and practice.
> In practice there is." -- Fortune Cookie
>


--
"In theory there is no difference between theory and practice.
In practice there is." -- Fortune Cookie

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 06:05:20PM -0000, Ross wrote:
> 
> When I test locally I get a weird error..
> 
> 
> CGI Error
> The specified CGI application misbehaved by not returning a complete set of 
> HTTP headers. The headers it did return are:
> 
> any ideas?
 
Not really, how did you set php up locally?  did you check your
webserver logs?

Curt.
-- 

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 11:16:15AM -0500, Leonard Burton wrote:
> Hi All,
> 
> I know that it is pretty darn impossible to come up with a regular
> expression for validating emails.
> 
> How do you all validated emails on form submission?
> 
> Is it good just to do something like "/[EMAIL PROTECTED]/"  ?  That (or a
> close derivative) should match that there is at least a @ and a . with
> chars before and after each.  I will be sending an email to each new
> registration with a confirmation link.

Since you will be validating emails via a confirmation link, i'd
probably suggest using the minimal testing, I dont think it is
worth the headache.  If you become to strict on your regex you
might eliminate something that is valid but the regex thought was
invalid.

At minimum [EMAIL PROTECTED] so to modify the regex a bit:

  /[EMAIL PROTECTED],}$/

Curt
--

--- End Message ---
--- Begin Message ---
I grabbed the following from a web-published article (sorry, can't remember
where):

function validate_email($email) {
        if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] 
)+(
\.[a-zA-Z0-9_-] +)+$/" , $email)){
                list($username,$domain)=split('@',$email);
                if(!customCheckDnsrr($domain)){
                        $valid = 0;
                } else {
                        $valid = 1;
                }
        } else {
                $valid = 0;
        }
        return $valid;
}
function customCheckDnsrr($host,$recType='') {
        if(!empty($host)) {
                if($recType=='') $recType="MX";
                        exec("nslookup -type=$recType $host",$output);
                        foreach($output as $line) {
                        if(preg_match("/^$host/", $line)) {
                                return true;
                        }
                }
                return false;
        }
        return false;
}
I think this covers a windows server (like mine), but there is a shorter one
for Linux (which I'm moving to in the near future).

Never tested this, so can't comment on usefulness.

George


> -----Original Message-----
> From: Curt Zirzow [mailto:[EMAIL PROTECTED]
> Sent: 16 November 2005 4:04 am
> To: [email protected]
> Subject: Re: [PHP] Validating Email addrs
>
>
> On Tue, Nov 15, 2005 at 11:16:15AM -0500, Leonard Burton wrote:
> > Hi All,
> >
> > I know that it is pretty darn impossible to come up with a regular
> > expression for validating emails.
> >
> > How do you all validated emails on form submission?
> >
> > Is it good just to do something like "/[EMAIL PROTECTED]/"  ?  That (or a
> > close derivative) should match that there is at least a @ and a . with
> > chars before and after each.  I will be sending an email to each new
> > registration with a confirmation link.
>
> Since you will be validating emails via a confirmation link, i'd
> probably suggest using the minimal testing, I dont think it is
> worth the headache.  If you become to strict on your regex you
> might eliminate something that is valid but the regex thought was
> invalid.
>
> At minimum [EMAIL PROTECTED] so to modify the regex a bit:
>
>   /[EMAIL PROTECTED],}$/
>
> Curt
> --
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message --- My question is simnple. I want to randomly select a row in a mysql table. I have a primary id.

<?php
$server = "localhost";
$user = "foo";
$pass = "foo";
$db="foo_db";
$table="foo_table";
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$sql = ??;

$news = mysql_query($sql) or die(print "<font color=red>".mysql_error()."</font>");
   while ($mydata = mysql_fetch_object($news))
   {
??
   }
?>

--- End Message ---
--- Begin Message ---
John Taylor-Johnston wrote:
My question is simnple. I want to randomly select a row in a mysql table. I have a primary id.

<?php
$server = "localhost";
$user = "foo";
$pass = "foo";
$db="foo_db";
$table="foo_table";
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$sql = ??;

$news = mysql_query($sql) or die(print "<font color=red>".mysql_error()."</font>");
   while ($mydata = mysql_fetch_object($news))
   {
??
   }
?>


If your table isn't too big, it's fine to do:

SELECT * FROM mytable ORDER BY RAND() LIMIT 1

If you've got more than a few 10,000s of rows, you might want to look at other ways, like selecting a random row based on the primary key by generating a random number in PHP before executing the SQL.

Jasper

--- End Message ---
--- Begin Message ---
On Wed, Nov 16, 2005 at 05:19:52PM +1300, Jasper Bryant-Greene wrote:
> John Taylor-Johnston wrote:
> >My question is simnple. I want to randomly select a row in a mysql 
> >table. I have a primary id.
> >
> ><?php
> >$server = "localhost";
> >$user = "foo";
> >$pass = "foo";
> >$db="foo_db";
> >$table="foo_table";
> >$myconnection = mysql_connect($server,$user,$pass);
> >mysql_select_db($db,$myconnection);
> >
> >$sql = ??;
> >
> >$news = mysql_query($sql) or die(print "<font 
> >color=red>".mysql_error()."</font>");
> >   while ($mydata = mysql_fetch_object($news))
> >   {
> >??
> >   }
> >?>
> >
> 
> If your table isn't too big, it's fine to do:
> 
> SELECT * FROM mytable ORDER BY RAND() LIMIT 1
> 
> If you've got more than a few 10,000s of rows, you might want to look at 
> other ways, like selecting a random row based on the primary key by 
> generating a random number in PHP before executing the SQL.

Very good idea on the 10,000+ rows, if you are dealing with large
tables order by rand() isn't very wise, there is one catch though
with using a random value from php.

Assuming you have a auto_increment for the primary key named 'id':
the first thing you need to do is get the max value of it:

  select max(id) from table
  
That isn't the catch, that query should be quicker than ~.0002
seconds or so :) The problem is you have to account for any deleted
records:

$min = 1; // mysql first auto_increment
list($max) = mysql_fetch_row(mysql_query("select max(id) from table"));
do {
  $rand = mt_rand($min, $max);

  $row = mysql_query("select * from table where id = $rand");
  if(mysql_errno() ) {
    break; // fook me.
  }
} while(! $row);

if ($row) {
  // we have a quick random row.
}

Depending on the space between deleted records, this most likely would
be more resource friendly (on large tables) than havning mysql sort
all the records to some tmp table (on disk) then sending only the first
record.

HTH,

Curt.
-- 

--- End Message ---
--- Begin Message ---
IS their a way to set the time to localtime instead of GMT in
the ini file?

Some users are complaining that they are seeing GMT, which this server
is set to.

-- 
Member - Liberal International  
This is [EMAIL PROTECTED]       Ici [EMAIL PROTECTED]
God Queen and country! Beware Anti-Christ rising!
Happy Christmas 2005 and Merry New Year 2006 

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--- End Message ---
--- Begin Message ---
On Mon, Nov 14, 2005 at 06:01:21PM -0400, Miles Thompson wrote:
> Can someone get rid of him?
> Every time I post, which I admit is not often, I get a bounce.

I put in a request to remove that email from the list, hopefully it
will get remove shortly.. i had to look in my gmail spam to find
that that adress is indeed responding back.

Curt.
-- 

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

How to uncompress  compressed data with php://input 

Which one of the following is correct 

1 .$unzip = gzinflate("php://input","r");
    $getdata =  fopen($unzip."r");

2. gzcompress("php://input","r");

  $getdata =  fopen($unzip."r");
 
what the best solution help me

With regards
Praveen


 




                
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

--- End Message ---
--- Begin Message ---
On Tue, Nov 15, 2005 at 09:28:22PM -0800, kumar kumar wrote:
> HI
> 
> How to uncompress  compressed data with php://input 
> 
> Which one of the following is correct 
> 
> 1 .$unzip = gzinflate("php://input","r");
>     $getdata =  fopen($unzip."r");
> 
> 2. gzcompress("php://input","r");
> 
>   $getdata =  fopen($unzip."r");
>  
> what the best solution help me

neither. 

I'm not sure what you expect to happen in both cases.  gzinflate
expects a string and returns a string.. which is invalid for
fopen().

with gzcompress (besides that the parameters being wrong) i dont
know how you expect it to uncompress, and it also returns a string
which is invalid for fopen().


perhaps you ment:

1)
  $getdata = gzopen('php://input', 'r');

  see: http://php.net/gzopen

22 
  $getdata = fopen('php://filter/gzinflate/resource=php://input');

  see: http://php.net/manual/en/filters.compression.php


Curt.
--

--- End Message ---

Reply via email to