php-general Digest 19 Aug 2009 07:52:37 -0000 Issue 6293

2009-08-19 Thread php-general-digest-help

php-general Digest 19 Aug 2009 07:52:37 - Issue 6293

Topics (messages 296941 through 296952):

Really quick try/catch question
296941 by: Brian Dunning
296942 by: Nathan Nobbe

PHP and CGI
296943 by: sono-io.fannullone.us
296944 by: Daevid Vincent
296945 by: Shawn McKenzie
296946 by: Shawn McKenzie
296948 by: sono-io.fannullone.us
296949 by: kranthi

Re: daemon without pcntl_fork
296947 by: Lars Torben Wilson
296952 by: Jim Lucas

Re: Undefined Offset Error with Pagination and Sessions
296950 by: kranthi

Re: getting the search words from a google query
296951 by: kranthi

Administrivia:

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

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

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


--
---BeginMessage---

I have a new SimpleXMLElement() that is occasionally throwing:
'Exception: String could not be parsed as XML'

Will this catch it when it happens, or am I missing something?

function domyfunction() {
// This does some stuff to exit the script gracefully
}

try {
$xmlobject = new SimpleXMLElement($xml);
} catch($e) {
domyfunction($e);
}


---End Message---
---BeginMessage---
On Tue, Aug 18, 2009 at 1:29 PM, Brian Dunning br...@briandunning.comwrote:

 I have a new SimpleXMLElement() that is occasionally throwing:
 'Exception: String could not be parsed as XML'

 Will this catch it when it happens, or am I missing something?

 function domyfunction() {
// This does some stuff to exit the script gracefully
 }

 try {
$xmlobject = new SimpleXMLElement($xml);
 } catch($e) {
domyfunction($e);
 }


you need to add the name of the class you want to capture, or an ancestor
thereof,

try {
  ..
} catch(Exception $e) {
 ..
}

-nathan
---End Message---
---BeginMessage---
	I've searched high and low for an answer to this.  Hopefully someone  
here might know.  Can PHP be used under a CGI?  I tried to put the  
following code on one of my perl shopping cart pages but it doesn't  
work:


?php
echo select name=\Year\;
for ($year = date(Y) ; $year = date(Y) + 8 ; $year++) {
echo option value=\$year\$year/option\n;
}
echo /select;
?

	 It works fine on a .php page.  I know that SSI will not work under  
CGI, so maybe it's the same for PHP.  Is there anyway to get this to  
work?


Thanks,
Frank
---End Message---
---BeginMessage---
 

 -Original Message-
 From: sono...@fannullone.us [mailto:sono...@fannullone.us] 
 Sent: Tuesday, August 18, 2009 5:10 PM
 To: PHP General List
 Subject: [PHP] PHP and CGI
 
   I've searched high and low for an answer to this.  
 Hopefully someone  
 here might know.  Can PHP be used under a CGI?  I tried to put the  
 following code on one of my perl shopping cart pages but it doesn't  
 work:
 
 ?php
 echo select name=\Year\;
 for ($year = date(Y) ; $year = date(Y) + 8 ; $year++) {
   echo option value=\$year\$year/option\n;
 }
 echo /select;
 ?
 
It works fine on a .php page.  I know that SSI will 
 not work under  
 CGI, so maybe it's the same for PHP.  Is there anyway to get this to  
 work?

Well, if you already have the page coded in Perl, why not just write those 5
lines in perl?!

It's a straight up for loop basically and some print statements. You're not
hitting a database or using anything remotely PHP-esque there.

I'm not so sure you can just mix and match parsers. I recall years ago some
talk of doing this, but I think it's just so rare and really impractical
that it's not worth setting up even if you can do it with some Apache magic.
Stick to one pre-processor language. Either all PHP or all Perl but not
both.

Daevid.

Some people, when confronted with a problem, think 'I know, I'll use XML.'
Now they have two problems. 

---End Message---
---BeginMessage---
sono...@fannullone.us wrote:
 I've searched high and low for an answer to this.  Hopefully someone
 here might know.  Can PHP be used under a CGI?  I tried to put the
 following code on one of my perl shopping cart pages but it doesn't work:
 
 ?php
 echo select name=\Year\;
 for ($year = date(Y) ; $year = date(Y) + 8 ; $year++) {
 echo option value=\$year\$year/option\n;
 }
 echo /select;
 ?
 
  It works fine on a .php page.  I know that SSI will not work under
 CGI, so maybe it's the same for PHP.  Is there anyway to get this to work?
 
 Thanks,
 Frank

PHP can run under CGI, however you're asking about mixing PHP with Perl.
 CGI != Perl.  CGI is the interface that your scripts have to the
programs that run them (i.e. Perl or PHP, etc...).

I've never done it, but to have both Perl and PHP parsed in one file,
you'd have to configure Apache (or your webserver) to parse the file
using PHP and then Perl.  Not sure if 

php-general Digest 19 Aug 2009 21:13:07 -0000 Issue 6294

2009-08-19 Thread php-general-digest-help

php-general Digest 19 Aug 2009 21:13:07 - Issue 6294

Topics (messages 296953 through 296984):

How to make sure that the target file to read is not under writing by others?
296953 by: Dengxule
296956 by: Ashley Sheridan
296957 by: Arno Kuhl
296958 by: Ashley Sheridan
296959 by: Arno Kuhl
296960 by: Ashley Sheridan
296961 by: Nitebirdz
296962 by: Kyle Smith
296964 by: Tom Worster
296965 by: Arno Kuhl
296966 by: Ashley Sheridan
296971 by: Arno Kuhl

Lots of fstat() calls in PHP 5.3
296954 by: Olga Khenkin

Re: daemon without pcntl_fork
296955 by: Per Jessen

PHP/Ajax Framework - Call for Developers  Testers
296963 by: Raymond Irving
296973 by: Nathan Nobbe

Re: DB Question | A hotel reservation scenario
296967 by: tedd
296979 by: Bob McConnell

Re: PHP and CGI
296968 by: tedd
296978 by: Ben Dunlap
296982 by: Bob McConnell

Re: Help on pregreplace
296969 by: tedd

Re: getting the search words from a google query
296970 by: Shawn McKenzie

Re: Another date exercise
296972 by: Shawn McKenzie
296974 by: Luke
296984 by: tedd

SESSIONS lost sometimes
296975 by: Angelo Zanetti
296976 by: Angelo Zanetti
296980 by: Ben Dunlap

mssql_bind Question
296977 by: David Stoltz

PDF Width
296981 by: Floyd Resler

Extract column names from a (my)SQL query
296983 by: דניאל דנון

Administrivia:

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

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

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


--
---BeginMessage---
Hi everyone:

I have a crontab command to execuate my php-script every half an hour.

The mission of the php-script is to open a file(log file), examine it.

The target file(log file) is transported to local every half an hour.

I've no idea how much time it will costs and on the other hand, i want to
make sure the file i'm openning is Completely Written.

Any instruction will be grateful.


PS: I've made a test. My php-script just fopen a local file being
transported in, and the fopen returns no FALSE value but a resource.


Dengxule
2009/08/19
---End Message---
---BeginMessage---
On Wed, 2009-08-19 at 15:55 +0800, Dengxule wrote:
 Hi everyone:
 
 I have a crontab command to execuate my php-script every half an hour.
 
 The mission of the php-script is to open a file(log file), examine it.
 
 The target file(log file) is transported to local every half an hour.
 
 I've no idea how much time it will costs and on the other hand, i want to
 make sure the file i'm openning is Completely Written.
 
 Any instruction will be grateful.
 
 
 PS: I've made a test. My php-script just fopen a local file being
 transported in, and the fopen returns no FALSE value but a resource.
 
 
 Dengxule
 2009/08/19

I had to do something similar in my last job. First thing to do is
figure out how large the log you expect to parse is going to be, and
from there, have a guess at how long it will take to transfer fully from
elsewhere.

I'd make the cron script a bit more frequent, but only ask it to look
for files that have changed between x and y minutes ago, where y is a
minute or two over the transfer duration. Then you can either mark the
file in some way, or move it to another location to indicate it has been
processed.

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



---End Message---
---BeginMessage---
-Original Message-
From: Dengxule [mailto:dengx...@gmail.com] 
Sent: 19 August 2009 09:56 AM
To: Php Maillist
Subject: [PHP] How to make sure that the target file to read is not under
writing by others?

Hi everyone:

I have a crontab command to execuate my php-script every half an hour.

The mission of the php-script is to open a file(log file), examine it.

The target file(log file) is transported to local every half an hour.

I've no idea how much time it will costs and on the other hand, i want to
make sure the file i'm openning is Completely Written.

Any instruction will be grateful.


PS: I've made a test. My php-script just fopen a local file being
transported in, and the fopen returns no FALSE value but a resource.


Dengxule
2009/08/19


Check the timestamp of the log file. Alternatively you can have a log
control file that is updated by the program transferring the log file only
when the transfer is completed, and work on that.

Cheers
Arno

---End Message---
---BeginMessage---
On Wed, 2009-08-19 at 11:55 +0200, Arno Kuhl wrote:
 -Original Message-
 From: Dengxule [mailto:dengx...@gmail.com] 
 Sent: 19 August 2009 09:56 AM
 To: Php Maillist
 Subject: [PHP] How to make sure that the target file to read is not under
 

Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Jim Lucas

Lars Torben Wilson wrote:

2009/8/18 Per Jessen p...@computer.org:

Jim Lucas wrote:


Does anybody know how to use PHP as a daemon without the use of
pcntl_fork.


Sure. Just start it and leave it running.


I want to launch a daemon out of the /etc/rc.local when the system
starts.

Yep, I do that all the time.


Anybody have any idea on how to do this?

On an openSUSE system I would just use 'startproc', but elsewhere you
could use setsid or nohup.  I.e. create your CLI script with a
hash-bang, then start it

nohup script 21 1/dev/null 


/Per


Again, that's not a daemon. If it is sufficient to run a background
process then that's fine, but that doesn't make it a daemon (although
it shares some things in common with a daemon). The background process
still has a controlling terminal (even if input and output have been
redirected), and a fully-implemented daemon will typically perform
other tasks which make it a good system citizen, such as: becoming
session leader, chroot'ing to / so that the filesystem it was started
from can be unmounted if necessary, and so on.

The difference may or may not be important, depending on the task at
hand. However, if an admin thinks he's got a daemon on his hands he
may wonder why things behave weird if what he really has is just
something which fakes it with  and nohup, since none of the important
daemon housekeeping has been dealt with.


Torben



Thanks for all the input you two!

Currently, I have two different uses for this startup script and daemon/bg 
process.

One will deal with a master server for one of my games and the second will be for running a PBX 
SMDR/CDR capturing tool.


The first must be able to deal with multiple simultaneous connections where as the second simply 
need to listen on the local serial port, connect to a remote IP:PORT, or attach itself to a IP:PORT 
and wait for input from another machine to be sent to it.  Once it receives the data, it simply 
parses it, sanitizes it, and stores it.


BUT ANYWAYS...

My system is OpenBSD 4.3 with PHP 5.2.8

Here is what I have come up with so far.  Looks to satisfying my needs:

tms_daemon
#! /bin/sh
#
# tms_daemon
#
#Starts a listening daemon that acts as a Tribes Master Server
#
# Author:  Jim Lucas jlu...@cmsws.com
#
# Version:  0.0.1
#

set -e

DESC=Tribes Master Server Daemon
DAEMON=/path/to/file/tms-0.1.5.php
PIDFILE=/var/run/tms.pid
SCRIPTNAME=/path/to/file/tms_daemon

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

#
#  Function that starts the daemon/service.
#
d_start() {
  if [ -f $PIDFILE ]; then
echo $DESC already running: PID# `cat $PIDFILE`
exit 1
  else
echo -n Starting $DESC
nohup $DAEMON 21 1/dev/null 
sleep 0.5
ps aux | grep $DAEMON | grep -v grep | awk -F' ' '{print $2}'  $PIDFILE
echo . [`cat $PIDFILE`]
  fi
}

#
#  Function that stops the daemon/service.
#
d_stop() {
  if [ -f $PIDFILE ]; then
echo -n Stopping $DESC
kill `cat $PIDFILE`
rm $PIDFILE
echo .
  else
echo $DESC is not running
exit 1
  fi
}

case $1 in
  start)
d_start
  ;;
  stop)
d_stop
  ;;
  status)
if [ -f $PIDFILE ]; then
  echo $DESC is running: PID# `cat $PIDFILE`
else
  echo $DESC is not running
fi
  ;;
  restart|force-reload)
d_stop
sleep 0.5
d_start
  ;;
  *)
echo Usage: $SCRIPTNAME {start|stop|restart|force-reload} 2
exit 1
  ;;
esac

exit 0
# END OF SCRIPT

Well, I realize this probably doesn't have much to do /directly/ with PHP, but it is a good exercise 
anyways.


I can start this from /etc/rc.local or from the cli and it does the same thing 
either way.

Comments and suggestions are welcome.  Please let me know if I can improve this 
at all.

TIA!

--
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] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Dengxule
Hi everyone:

I have a crontab command to execuate my php-script every half an hour.

The mission of the php-script is to open a file(log file), examine it.

The target file(log file) is transported to local every half an hour.

I've no idea how much time it will costs and on the other hand, i want to
make sure the file i'm openning is Completely Written.

Any instruction will be grateful.


PS: I've made a test. My php-script just fopen a local file being
transported in, and the fopen returns no FALSE value but a resource.


Dengxule
2009/08/19


[PHP] Lots of fstat() calls in PHP 5.3

2009-08-19 Thread Olga Khenkin
Hi,

We recently upgraded our web servers with PHP 5.3 and found out that
there are lots of fstat() calls. fstat() is called 3 times on each file
open. Do you know why this happens and how can these calls be reduced? 

We're running Red Hat 3.4.6, Apache 2.0.59, PHP 5.3.0 with APC.

Here's strace example (I replaced full paths by [PATH]):

open([PATH]/RecommendationsManager.php, O_RDONLY) = 19
fstat(19, {st_mode=S_IFREG|0777, st_size=16937, ...}) = 0
fstat(19, {st_mode=S_IFREG|0777, st_size=16937, ...}) = 0
fstat(19, {st_mode=S_IFREG|0777, st_size=16937, ...}) = 0
mmap(NULL, 16937, PROT_READ, MAP_SHARED, 19, 0) = 0x2a9f441000
stat[PATH]RecommendationsManager.php, {st_mode=S_IFREG|0777,
st_size=16937, ...}) = 0
munmap(0x2a9f441000, 16937) = 0
close(19)   = 0
open[PATH]/Recommendations.php, O_RDONLY) = 19
fstat(19, {st_mode=S_IFREG|0777, st_size=10695, ...}) = 0
fstat(19, {st_mode=S_IFREG|0777, st_size=10695, ...}) = 0
fstat(19, {st_mode=S_IFREG|0777, st_size=10695, ...}) = 0
mmap(NULL, 10695, PROT_READ, MAP_SHARED, 19, 0) = 0x2a9f441000
stat([PATH]/Recommendations.php, {st_mode=S_IFREG|0777, st_size=10695,
...}) = 0
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2a9f444000
munmap(0x2a9f441000, 10695) = 0
close(19)   = 0


Thanks,
Olga.

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



Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Per Jessen
Jim Lucas wrote:

 Currently, I have two different uses for this startup script and
 daemon/bg process.
 
 One will deal with a master server for one of my games and the second
 will be for running a PBX SMDR/CDR capturing tool.
 
 The first must be able to deal with multiple simultaneous connections
 where as the second simply need to listen on the local serial port,
 connect to a remote IP:PORT, or attach itself to a IP:PORT
 and wait for input from another machine to be sent to it.  Once it
 receives the data, it simply parses it, sanitizes it, and stores it.

I probably wouldn't have chosen PHP for the first one, but there's no
reason it shouldn't work.  For the second one, did you mean to
write serial port?  That's a bit of a different animal, I'm not sure
how far you'll get with php.

 Here is what I have come up with so far.  Looks to satisfying my
 needs:
 
 tms_daemon
[snip]
 # END OF SCRIPT

Looks good to me. It'll certainly do the job.


/Per

-- 
Per Jessen, Zürich (22.5°C)


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



Re: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Ashley Sheridan
On Wed, 2009-08-19 at 15:55 +0800, Dengxule wrote:
 Hi everyone:
 
 I have a crontab command to execuate my php-script every half an hour.
 
 The mission of the php-script is to open a file(log file), examine it.
 
 The target file(log file) is transported to local every half an hour.
 
 I've no idea how much time it will costs and on the other hand, i want to
 make sure the file i'm openning is Completely Written.
 
 Any instruction will be grateful.
 
 
 PS: I've made a test. My php-script just fopen a local file being
 transported in, and the fopen returns no FALSE value but a resource.
 
 
 Dengxule
 2009/08/19

I had to do something similar in my last job. First thing to do is
figure out how large the log you expect to parse is going to be, and
from there, have a guess at how long it will take to transfer fully from
elsewhere.

I'd make the cron script a bit more frequent, but only ask it to look
for files that have changed between x and y minutes ago, where y is a
minute or two over the transfer duration. Then you can either mark the
file in some way, or move it to another location to indicate it has been
processed.

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




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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Arno Kuhl
-Original Message-
From: Dengxule [mailto:dengx...@gmail.com] 
Sent: 19 August 2009 09:56 AM
To: Php Maillist
Subject: [PHP] How to make sure that the target file to read is not under
writing by others?

Hi everyone:

I have a crontab command to execuate my php-script every half an hour.

The mission of the php-script is to open a file(log file), examine it.

The target file(log file) is transported to local every half an hour.

I've no idea how much time it will costs and on the other hand, i want to
make sure the file i'm openning is Completely Written.

Any instruction will be grateful.


PS: I've made a test. My php-script just fopen a local file being
transported in, and the fopen returns no FALSE value but a resource.


Dengxule
2009/08/19


Check the timestamp of the log file. Alternatively you can have a log
control file that is updated by the program transferring the log file only
when the transfer is completed, and work on that.

Cheers
Arno


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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Ashley Sheridan
On Wed, 2009-08-19 at 11:55 +0200, Arno Kuhl wrote:
 -Original Message-
 From: Dengxule [mailto:dengx...@gmail.com] 
 Sent: 19 August 2009 09:56 AM
 To: Php Maillist
 Subject: [PHP] How to make sure that the target file to read is not under
 writing by others?
 
 Hi everyone:
 
 I have a crontab command to execuate my php-script every half an hour.
 
 The mission of the php-script is to open a file(log file), examine it.
 
 The target file(log file) is transported to local every half an hour.
 
 I've no idea how much time it will costs and on the other hand, i want to
 make sure the file i'm openning is Completely Written.
 
 Any instruction will be grateful.
 
 
 PS: I've made a test. My php-script just fopen a local file being
 transported in, and the fopen returns no FALSE value but a resource.
 
 
 Dengxule
 2009/08/19
 
 
 Check the timestamp of the log file. Alternatively you can have a log
 control file that is updated by the program transferring the log file only
 when the transfer is completed, and work on that.
 
 Cheers
 Arno
 
 
The log control file wouldn't work, as how would you know when to open
the control file?!

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




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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Arno Kuhl
-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: 19 August 2009 11:57 AM
To: a...@dotcontent.net
Cc: 'Dengxule'; 'Php Maillist'
Subject: RE: [PHP] How to make sure that the target file to read is not
under writing by others?

On Wed, 2009-08-19 at 11:55 +0200, Arno Kuhl wrote:
 -Original Message-
 From: Dengxule [mailto:dengx...@gmail.com]
 Sent: 19 August 2009 09:56 AM
 To: Php Maillist
 Subject: [PHP] How to make sure that the target file to read is not 
 under writing by others?
 
 Hi everyone:
 
 I have a crontab command to execuate my php-script every half an hour.
 
 The mission of the php-script is to open a file(log file), examine it.
 
 The target file(log file) is transported to local every half an hour.
 
 I've no idea how much time it will costs and on the other hand, i want 
 to make sure the file i'm openning is Completely Written.
 
 Any instruction will be grateful.
 
 
 PS: I've made a test. My php-script just fopen a local file being 
 transported in, and the fopen returns no FALSE value but a resource.
 
 
 Dengxule
 2009/08/19
 
 
 Check the timestamp of the log file. Alternatively you can have a log 
 control file that is updated by the program transferring the log file 
 only when the transfer is completed, and work on that.
 
 Cheers
 Arno
 
 
The log control file wouldn't work, as how would you know when to open the
control file?!

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

--

You can open the control file any time you want. The info in the control
file tells you whether to proceed. The transfer program adds the entry when
the log has been transferred, the processing script updates the entry to
indicate it's been processed. You can either add a new entry each time
(useful for monitoring to fine-tune the timing, or for keeping a history) or
work on a single entry that's overwritten each time the log is transferred.

Cheers
Arno


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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Ashley Sheridan
On Wed, 2009-08-19 at 12:56 +0200, Arno Kuhl wrote:
 -Original Message-
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
 Sent: 19 August 2009 11:57 AM
 To: a...@dotcontent.net
 Cc: 'Dengxule'; 'Php Maillist'
 Subject: RE: [PHP] How to make sure that the target file to read is not
 under writing by others?
 
 On Wed, 2009-08-19 at 11:55 +0200, Arno Kuhl wrote:
  -Original Message-
  From: Dengxule [mailto:dengx...@gmail.com]
  Sent: 19 August 2009 09:56 AM
  To: Php Maillist
  Subject: [PHP] How to make sure that the target file to read is not 
  under writing by others?
  
  Hi everyone:
  
  I have a crontab command to execuate my php-script every half an hour.
  
  The mission of the php-script is to open a file(log file), examine it.
  
  The target file(log file) is transported to local every half an hour.
  
  I've no idea how much time it will costs and on the other hand, i want 
  to make sure the file i'm openning is Completely Written.
  
  Any instruction will be grateful.
  
  
  PS: I've made a test. My php-script just fopen a local file being 
  transported in, and the fopen returns no FALSE value but a resource.
  
  
  Dengxule
  2009/08/19
  
  
  Check the timestamp of the log file. Alternatively you can have a log 
  control file that is updated by the program transferring the log file 
  only when the transfer is completed, and work on that.
  
  Cheers
  Arno
  
  
 The log control file wouldn't work, as how would you know when to open the
 control file?!
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 --
 
 You can open the control file any time you want. The info in the control
 file tells you whether to proceed. The transfer program adds the entry when
 the log has been transferred, the processing script updates the entry to
 indicate it's been processed. You can either add a new entry each time
 (useful for monitoring to fine-tune the timing, or for keeping a history) or
 work on a single entry that's overwritten each time the log is transferred.
 
 Cheers
 Arno
 
 
No, what you're saying is 'use a log file in order to know when to look
at another log file'. What would happen if you tried to access the
control log file whilst it was in the process of being written to?
Admittedly, you reduce your chances of failure because there is less
data being written to the control log than the actual log, but the
chance of reading incomplete data is still there!

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




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



Re: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Nitebirdz
On Wed, Aug 19, 2009 at 11:59:39AM +0100, Ashley Sheridan wrote:
  
 No, what you're saying is 'use a log file in order to know when to look
 at another log file'. What would happen if you tried to access the
 control log file whilst it was in the process of being written to?
 Admittedly, you reduce your chances of failure because there is less
 data being written to the control log than the actual log, but the
 chance of reading incomplete data is still there!
 

WARNING: total newbie here.

If I understood Arno correctly, he was recommending to implement
something like the old /var/run/*pid files in UNIX.  That way, you can
control whether or not the previous run is already done with the file
before you move on.  


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



Re: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Kyle Smith

Nitebirdz wrote:

On Wed, Aug 19, 2009 at 11:59:39AM +0100, Ashley Sheridan wrote:
  
 
No, what you're saying is 'use a log file in order to know when to look

at another log file'. What would happen if you tried to access the
control log file whilst it was in the process of being written to?
Admittedly, you reduce your chances of failure because there is less
data being written to the control log than the actual log, but the
chance of reading incomplete data is still there!




WARNING: total newbie here.

If I understood Arno correctly, he was recommending to implement
something like the old /var/run/*pid files in UNIX.  That way, you can
control whether or not the previous run is already done with the file
before you move on. 
That is definitely the correct approach.  Have the script which copies 
the log file touch a file called 'log_file.write' or some such.  When 
it's done, remove the file.  Your PHP script should exit if that file 
exists.  Of course, given the 30 minute cron cycle, it would then have 
to wait until the next cycle.  Maybe run it more often.


[PHP] PHP/Ajax Framework - Call for Developers Testers

2009-08-19 Thread Raymond Irving
Hello,

I've just released Raxan Beta 2 with lots for features for both PHP and Ajax 
developers.

I'm looking for persons to help me test and improve the framework. If you're 
interested, then please download the framework , join the community and share 
your thoughts and ideas. Feel free to send me an email if you have any 
questions.

You can check out the new features here:
http://raxanpdi.com/new-in-beta-2.html


Best regards
__
Raymond Irving


Re: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Tom Worster
On 8/19/09 3:55 AM, Dengxule dengx...@gmail.com wrote:

 I have a crontab command to execuate my php-script every half an hour.
 
 The mission of the php-script is to open a file(log file), examine it.
 
 The target file(log file) is transported to local every half an hour.
 
 I've no idea how much time it will costs and on the other hand, i want to
 make sure the file i'm openning is Completely Written.
 
 Any instruction will be grateful.

perhaps you could use cronolog (http://cronolog.org/) to rotate the log
files every half hour? that way you could be sure that the file you open to
process/copy is one that cronolog has finished writing to.



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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Arno Kuhl
-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: 19 August 2009 01:00 PM
To: a...@dotcontent.net
Cc: 'Dengxule'; 'Php Maillist'
Subject: RE: [PHP] How to make sure that the target file to read is not
under writing by others?

On Wed, 2009-08-19 at 12:56 +0200, Arno Kuhl wrote:
 -Original Message-
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
 Sent: 19 August 2009 11:57 AM
 To: a...@dotcontent.net
 Cc: 'Dengxule'; 'Php Maillist'
 Subject: RE: [PHP] How to make sure that the target file to read is 
 not under writing by others?
 
 On Wed, 2009-08-19 at 11:55 +0200, Arno Kuhl wrote:
  -Original Message-
  From: Dengxule [mailto:dengx...@gmail.com]
  Sent: 19 August 2009 09:56 AM
  To: Php Maillist
  Subject: [PHP] How to make sure that the target file to read is not 
  under writing by others?
  
  Hi everyone:
  
  I have a crontab command to execuate my php-script every half an hour.
  
  The mission of the php-script is to open a file(log file), examine it.
  
  The target file(log file) is transported to local every half an hour.
  
  I've no idea how much time it will costs and on the other hand, i 
  want to make sure the file i'm openning is Completely Written.
  
  Any instruction will be grateful.
  
  
  PS: I've made a test. My php-script just fopen a local file being 
  transported in, and the fopen returns no FALSE value but a resource.
  
  
  Dengxule
  2009/08/19
  
  
  Check the timestamp of the log file. Alternatively you can have a 
  log control file that is updated by the program transferring the log 
  file only when the transfer is completed, and work on that.
  
  Cheers
  Arno
  
  
 The log control file wouldn't work, as how would you know when to open 
 the control file?!
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 --
 
 You can open the control file any time you want. The info in the 
 control file tells you whether to proceed. The transfer program adds 
 the entry when the log has been transferred, the processing script 
 updates the entry to indicate it's been processed. You can either add 
 a new entry each time (useful for monitoring to fine-tune the timing, 
 or for keeping a history) or work on a single entry that's overwritten
each time the log is transferred.
 
 Cheers
 Arno
 
 
No, what you're saying is 'use a log file in order to know when to look at
another log file'. What would happen if you tried to access the control log
file whilst it was in the process of being written to?
Admittedly, you reduce your chances of failure because there is less data
being written to the control log than the actual log, but the chance of
reading incomplete data is still there!

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



A control file is used to control processing, a log file is used to log
events. I'm definitely talking about a control file. If the control file
happens to keep a log then it's a bonus, but not its primary purpose.

Access the control file while being written to? I'm talking about a short
single-line entry, and the file is only written to when the write command is
processed. Copying a file is very different to issuing a single write
command. Don't forget that PHP and webservers run on top of operating
systems, and the OS ultimately handles all file activity. The OS ensures
that another process can't read a file that is halfway through a write
command (any computer would instantly crash if that sort of basic
housekeeping wasn't done). 

If you don't trust the OS then file locking can be used (though pointless in
this case). For the ultra-paranoids who don't trust OS's or locks you can
either (a) choose a different career, or (b) add a time-stamp to the
beginning of the entry and check that the entry wasn't written in the last
few nanoseconds (if you get this far I'd recommend option a). You can even
go so far as to check the length of the timestamp string to be sure that you
got all of it, and if it's too short you know you're busy reading a file
that's halfway through a write command, and sleep for a millisecond and then
try again ;)

Cheers
Arno


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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Ashley Sheridan
On Wed, 2009-08-19 at 15:31 +0200, Arno Kuhl wrote:
 (any computer would instantly crash if that sort of basic
 housekeeping wasn't done)

No, it really wouldn't! If it did, then you'd never have video playing
software out there that supported broken downloads, no preview software
for semi-downloaded items. Have you ever been sent a large jpeg over a
slow connection on a messenger program? You can open the file way before
it's finished downloading and actually see it progressively load in.

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




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



Re: [PHP] DB Question | A hotel reservation scenario

2009-08-19 Thread tedd

At 2:46 PM -0400 8/18/09, Floyd Resler wrote:
I would create a room history table that contained three fields: 
room number, status, date stamp.  Each time the status of a room 
changes insert a new record into the table with the current status 
and date/time.


Take care,
Floyd


That's the way I would handle it -- clean and simple.

That way not only would have have the current status of each room, 
but you could use that data to perform all sorts of analysis, such as 
which rooms are most popular, what dates provide the most traffic, 
which rooms may need more maintenance, and so on.


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] PHP and CGI

2009-08-19 Thread tedd

At 5:10 PM -0700 8/18/09, sono...@fannullone.us wrote:
	I've searched high and low for an answer to this.  Hopefully 
someone here might know.  Can PHP be used under a CGI?  I tried to 
put the following code on one of my perl shopping cart pages but it 
doesn't work:


?php
echo select name=\Year\;
for ($year = date(Y) ; $year = date(Y) + 8 ; $year++) {
echo option value=\$year\$year/option\n;
}
echo /select;
?

	 It works fine on a .php page.  I know that SSI will not work 
under CGI, so maybe it's the same for PHP.  Is there anyway to get 
this to work?


Thanks,
Frank



Frank:

I won't guarantee that this will work, but it's worth a try.

In your .htacess file add this:

# handler for phpsuexec. -- makes following prefixes considered for php
FilesMatch \.(htm|html|pl)$
 SetHandler application/x-httpd-php
/FilesMatch

If it works, let me know.

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



[PHP] Re: Help on pregreplace

2009-08-19 Thread tedd

At 10:51 AM -0400 8/18/09, Al wrote:

Merlin Morgenstern wrote:

Hi there,

I am highlighting keywords with the help of pregreplace. This works 
great with one limitation. If the word that has to be replaced 
contains a slash, preg throws an error. So far I could not find a 
fix. Can someone help?


Here is the code:

   
   $pattern = /\b($words)\b/is;

   $replace = 'span style=background:#FF;color:#FC;\\1/span';
   return preg_replace($pattern,$replace,$str);

Thank you in advance,

Merlin


best insurance

http://us2.php.net/manual/en/function.preg-quote.php


In addition, you might consider moving your style attributes to a 
style sheet and then using a class name like so:


  $replace = 'span class=highlight\\1/span';

That way you can change highlighting as you want without altering your code.

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



[PHP] Re: getting the search words from a google query

2009-08-19 Thread Shawn McKenzie
MURTUZA KUTUB   wrote:
 hey,
 
 i am a beginner at php and i need your help.
 
 i have a list of urls visited on a particular day in mysql database.
 using php i find out all the websites that have a google search.
 now i need to strip apart the google query from the entire url.
 i think parse function is used for it but i am not sure how it is used etc.
 
 if possible plz send me a small snippet as an example.
 
 cheers.
 
 -
 Bits-Pilani Goa Campus (http://www.bits-goa.ac.in)
 

?php

$url =
http://www.google.com/search?q=phpie=utf-8oe=utf-8aq=trls=com.ubuntu:en-US:unofficialclient=firefox-a;;

$url_parts = parse_url($url);

print_r($url_parts);

parse_str($url_parts['query'], $query_vars);

print_r($query_vars);

?

Array
(
[scheme] = http
[host] = www.google.com
[path] = /search
[query] =
q=phpie=utf-8oe=utf-8aq=trls=com.ubuntu:en-US:unofficialclient=firefox-a
)
Array
(
[q] = php
[ie] = utf-8
[oe] = utf-8
[aq] = t
[rls] = com.ubuntu:en-US:unofficial
[client] = firefox-a
)

Normally for Google the 'q' var is the search term, in this case 'php'.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



RE: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Arno Kuhl
-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: 19 August 2009 03:34 PM
To: a...@dotcontent.net
Cc: 'Dengxule'; 'Php Maillist'
Subject: RE: [PHP] How to make sure that the target file to read is not
under writing by others?

On Wed, 2009-08-19 at 15:31 +0200, Arno Kuhl wrote:
 (any computer would instantly crash if that sort of basic housekeeping 
 wasn't done)

No, it really wouldn't! If it did, then you'd never have video playing
software out there that supported broken downloads, no preview software for
semi-downloaded items. Have you ever been sent a large jpeg over a slow
connection on a messenger program? You can open the file way before it's
finished downloading and actually see it progressively load in.

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

---

If anyone was left a bit unsure about whether or not a write command in PHP
could result in a file on a local filesystem being left in a semi-written
state (i.e. some other script started reading the file while your script had
only written part of its output string) rest assured that fwrite() always
writes *all* the contents to the file without the need of flock(), by the
time any other process (whether PHP or not) reads that file (assuming you're
not writing megabytes of data with a single fwrite()). To quote the PHP
manual:

If handle was fopen()ed in append mode, fwrite()s are atomic (unless the
size of string exceeds the filesystem's block size, on some platforms, and
as long as the file is on a local filesystem). That is, there is no need to
flock() a resource before calling fwrite(); all of the data will be written
without interruption.

Cheers
Arno


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



Re: [PHP] Re: PHP and CGI

2009-08-19 Thread Ben Dunlap
        That's exactly the case.  I have been running my business on a Perl
 cart for the last 5+ years, and I can't switch to a PHP cart just yet.  I
 was just hoping to add some functionality with PHP.  Perl was much harder

It would probably bomb your performance but you could always call a
separate PHP script from your Perl code:

#!/usr/bin/perl

# do some stuff in perl

my $php_output = `/usr/bin/php whatever.php`

# do something with $php_output

1;

If you're just looking to add some features quickly to your existing
Perl code: Have you searched CPAN for what you need?

Ben

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



RE: [PHP] DB Question | A hotel reservation scenario

2009-08-19 Thread Bob McConnell
From: Ashley Sheridan
 On Tue, 2009-08-18 at 19:15 +0430, Behzad wrote:
 
 I'm faced with an interesting and challenging problem.
 
 Consider a database, designed for a hotel.
 At any given time, each room has a different status: It's Busy or
Reserved,
 or Free.
 
 It's easy to retrieve number of Free rooms at the current time.
 But how can I count the number of rooms that were busy during the
last week
 ?
 
 I would appreciate if you take a brief moment of your time and share
your
 opinion.
 
 Keep a table that lists all the rooms along with their current status
 
 Keep another table that has these fields:
   * room_id (the id from above table)
   * status (enumerated value - 'busy','reserved')
   * start_date
   * end_date
 
 Then you perform your query using a join of these two tables, within a
 particular date range. I've left out 'free' from the second table
 because there's no point updating the table for a period if a room is
 not being used.
 
 You could also have start_date and end_date as datetime fields, as
every
 hotel i've ever been in has a set time for check-in and another for
 check-out.

It would be easier if you kept a record of the status changes to and
from busy (check-in and check-out) as a transaction log. Then you can
scan the log to see the status changes for any time period. But you
still have to deal with a room that stayed busy for the entire period.

First question, does busy include the time needed by housekeeping to
clean the room after checkout? You might want to consider a separate
status for that.

Second question, does the system keep track of when each room is
reserved? If one is reserved for three nights beginning Friday, can it
still be used Wednesday for a one or two night stay?

Bob McConnell

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



Re: [PHP] SESSIONS lost sometimes

2009-08-19 Thread Ben Dunlap
 We have a server with a site that does some XML calls. After lots of testing
 I have found that the server is losing session variables.
[8]
 Also the site goes from HTTP to HTTPS at some point but this isn't the issue
 as it loses the sessions as soon as they are set sometimes.

 Therefore I would like to know what I could check. I have read in other

Can you clarify what you mean by losing sessions? Have you taken a
network trace to see whether the client is consistently sending the
session ID with every request?

When the problem happens, is $_SESSION completely empty or is it only
missing some variables? Does it seem to happen on any page, or only
certain ones?

Thanks,

Ben

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



[PHP] PDF Width

2009-08-19 Thread Floyd Resler

Does anyone know how I can find the width of a PDF in PHP?

Thanks!
Floyd


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



RE: [PHP] Re: PHP and CGI

2009-08-19 Thread Bob McConnell
From: sono...@fannullone.us
 On Aug 18, 2009, at 7:13 PM, Shawn McKenzie wrote:

 P.S.  Does anyone know of a good Perl mailing list?

beginn...@perl.org

Or you can try www.perlmonks.org.

Bob McConnell

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



[PHP] Extract column names from a (my)SQL query

2009-08-19 Thread דניאל דנון
Lets assume I have the following string:
SELECT field1, field2, field3 FROM tablename WHERE field1 = 'something' 

Is there any way to get field1, field2, field3? assuming it might also
have join, left join - things like that.

I can easily do it with preg_match, but I have to make sure its foolproof.
It would be a lot better if it will also be able to parse the whole query -
catch limit, where, joins, comments


Is there any php class that could do it?

I've looked in the pear site and on Google but haven't had any luck.

-- 
Use ROT26 for best security


Re: [PHP] Another date exercise

2009-08-19 Thread tedd

At 10:43 AM -0500 8/19/09, Shawn McKenzie wrote:

  First stab at it.  Of course it needs US date ordering (month day year).

  You can't do euro type dates or any other format because there is no
 way to tell the difference between 1/2/2009 (January) and 1/2/2009
 (February):

 ?php

 $dates = array(
 'August 5, 2009',
 'Aug 05 2009',
 'Aug 5, 9',
 '08/05/09',
 '8-5-9',
 '8 05 2009',
 '8,5,9',);

 foreach($dates as $date) {
 $date = preg_replace(#([\d])+[^/\d]+([\d]+)[^/\d]+([\d]+)#,
 $1/$2/$3, $date);
 echo date(M j, Y, strtotime($date)) .\n;
 }

 ?



Guess you didn't like this one?  Also, if you change the / to - in the
preg_replace() it should work on Euro style dates.

$date = preg_replace(#([\d])+[^-\d]+([\d]+)[^-\d]+([\d]+)#,
$1-$2-$3, $date);

-Shawn


-Shawn:

Thanks, but my idea was more along the lines of this:

http://php1.net/b/date-picker/index.php

It's not thoroughly tested, but thus far it works.

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] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Clancy
On Wed, 19 Aug 2009 08:13:56 -0400, kyle.sm...@inforonics.com (Kyle Smith) 
wrote:

Nitebirdz wrote:
 On Wed, Aug 19, 2009 at 11:59:39AM +0100, Ashley Sheridan wrote:
   
  
 No, what you're saying is 'use a log file in order to know when to look
 at another log file'. What would happen if you tried to access the
 control log file whilst it was in the process of being written to?
 Admittedly, you reduce your chances of failure because there is less
 data being written to the control log than the actual log, but the
 chance of reading incomplete data is still there!

 

 WARNING: total newbie here.

 If I understood Arno correctly, he was recommending to implement
 something like the old /var/run/*pid files in UNIX.  That way, you can
 control whether or not the previous run is already done with the file
 before you move on. 
That is definitely the correct approach.  Have the script which copies 
the log file touch a file called 'log_file.write' or some such.  When 
it's done, remove the file.  Your PHP script should exit if that file 
exists.  Of course, given the 30 minute cron cycle, it would then have 
to wait until the next cycle.  Maybe run it more often.

I gather from this discussion that PHP allows two users to open a file for R/W? 
I had
assumed it wouldn't.

Anyway, how about:

$user = 'Fred'; $try_again = true;
If (!file_exists('Busy.txt'))
{
File_put_contents ('Busy.txt', $user);
If ($user == File_get_contents ('Busy.txt')
{
// Do what you have to
Unlink ('Busy.txt');
$try_again = false;
}
}
if ($try_again)
{
// Come back in 5 minutes
}

This has a theoretical weakness, in that Joe could check for Busy.txt in the 
interval
between your checking and writing it, and then write his copy after you had 
read your
copy. A moments delay between writing and re-reading would fix this.


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



Re: [PHP] PHP/Ajax Framework - Call for Developers Testers

2009-08-19 Thread Raymond Irving
Hi Nathan,

Many thanks for the feedback. There many other useful features built into the 
API but my favorite is the embedded feature.

You can see a live example here:
http://raxanpdi.com/shoutbox-embedded-example.html

Best regards,
__
Raymond Irving


--- On Wed, 8/19/09, Nathan Nobbe quickshif...@gmail.com wrote:

From: Nathan Nobbe quickshif...@gmail.com
Subject: Re: [PHP] PHP/Ajax Framework - Call for Developers  Testers
To: Raymond Irving xwis...@yahoo.com
Cc: php-general@lists.php.net
Date: Wednesday, August 19, 2009, 11:56 AM

On Wed, Aug 19, 2009 at 7:06 AM, Raymond Irving xwis...@yahoo.com wrote:

 Hello,

 I've just released Raxan Beta 2 with lots for features for both PHP and
 Ajax developers.

 I'm looking for persons to help me test and improve the framework. If
 you're interested, then please download the framework , join the community
 and share your thoughts and ideas. Feel free to send me an email if you have
 any questions.

 You can check out the new features here:
 http://raxanpdi.com/new-in-beta-2.html


you have a neat feature list here Raymond, thanks for sharing.

-nathan