Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Jim Lucas

Lars Torben Wilson wrote:

2009/8/18 Per Jessen :

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 

[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"  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:


";
for ($year = date("Y") ; $year <= date("Y") + 8 ; $year++) {
echo "$year\n";
}
echo "";
?>

	 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

 SetHandler application/x-httpd-php


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 = '\\1';
   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 = '\\1';

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

http://www.google.com/search?q=php&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=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=php&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=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] Another date exercise

2009-08-19 Thread Shawn McKenzie
Shawn McKenzie wrote:
> tedd wrote:
>> At 3:40 PM +0530 8/17/09, kranthi wrote:
>>> dont you think http://in3.php.net/strtotime is a solution to your
>>> problem ?
>> No, it's not a solution to my problem -- I have he problem solved.
>>
>> I was just asking if anyone wanted to submit their php solution. It was
>> only an exercise.
>>
>> I know there are numerous javascript solutions (some good, some bad),
>> but ALL of their data has to be accepted and scrubbed by a php script
>> anyway, so I was suggesting creating a php script to do it.
>>
>> If it's not a good exercise, then don't do it.
> 
> 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):
> 
>  
> $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

-- 
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 Nathan Nobbe
On Wed, Aug 19, 2009 at 7:06 AM, Raymond Irving  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


Re: [PHP] Another date exercise

2009-08-19 Thread Luke
2009/8/19 Shawn McKenzie 

> Shawn McKenzie wrote:
> > tedd wrote:
> >> At 3:40 PM +0530 8/17/09, kranthi wrote:
> >>> dont you think http://in3.php.net/strtotime is a solution to your
> >>> problem ?
> >> No, it's not a solution to my problem -- I have he problem solved.
> >>
> >> I was just asking if anyone wanted to submit their php solution. It was
> >> only an exercise.
> >>
> >> I know there are numerous javascript solutions (some good, some bad),
> >> but ALL of their data has to be accepted and scrubbed by a php script
> >> anyway, so I was suggesting creating a php script to do it.
> >>
> >> If it's not a good exercise, then don't do it.
> >
> > 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):
> >
> >  >
> > $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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Perhaps you could detect the region of the user to pick which kind of date
to use

-- 
Luke Slater
:O)

this text is protected by international copyright. it is illegal for
anybody apart from the recipient to keep a copy of this text.
dieser text wird von internationalem urheberrecht geschuetzt. allen
ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
zu behalten.


[PHP] SESSIONS lost sometimes

2009-08-19 Thread Angelo Zanetti
Dear all, 

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.

However sometimes it isn't losing them so I don't think it's a code thing
rather a server issue. The strange thing is that its not consistent.
Things to note: 

The session array is really big, quite a few variables.

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
posts that I should check:

-Disk space

-Garbage collection running too frequently and reducing  
session lifetime in an ini_set and it might be possible that my live
sessions are being  
erronously treated as garbage.

-Is there any other settings that I can check or should the above be all I
should check


Please any advise, comments, help is appreciated.

Thanks in advance.

Angelo
http://www.elemental.co.za


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



[PHP] SESSIONS lost sometimes

2009-08-19 Thread Angelo Zanetti
Dear all, 

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.

However sometimes it isn't losing them so I don't think it's a code thing
rather a server issue. The strange thing is that its not consistent.
Things to note: 

The session array is really big, quite a few variables.

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
posts that I should check:

-Disk space

-Garbage collection running too frequently and reducing session lifetime in
an ini_set and it might be possible that my live sessions are being
erronously treated as garbage.

-Is there any other settings that I can check or should the above be all I
should check


Please any advise, comments, help is appreciated.

Thanks in advance.

Angelo
http://www.elemental.co.za


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



[PHP] mssql_bind Question

2009-08-19 Thread David Stoltz
Code in question:
mssql_bind($stmt,
'@managerName',$managerName,SQLVARCHAR,false,false,50);

For a normal varchar field, the length is obvious, in this case 50.

But for an ntext field, how do I use the mssql_bind statement?

Far as I know, these are the only available "types" to use:
SQLTEXT, SQLVARCHAR, SQLCHAR, SQLINT1, SQLINT2, SQLINT4, SQLBIT,
SQLFLT4, SQLFLT8, SQLFLTN

I need to use which type, and what length to use...?

Thanks for any advice...


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

 



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

From: Nathan Nobbe 
Subject: Re: [PHP] PHP/Ajax Framework - Call for Developers & Testers
To: "Raymond Irving" 
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  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


Re: [PHP] daemon without pcntl_fork

2009-08-19 Thread Lars Torben Wilson
2009/8/19 Per Jessen :
> Jim Lucas wrote:

[snip]

> 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

I agree with Per on all points--I probably wouldn't choose PHP as a
first choice for the first task, but the startup script you have shown
looks like a bog-standard startup script and should serve you well. I
haven't really gone over it with a fine-toothed comb though. Typos
etc. are still up to to you. :) Of course, the whole thing depends on
how tms_daemon behaves, but the startup script looks OK.

Can you explain in a bit more detail exactly what the second part (the
serial-network data logger) needs to do? I've written similar daemons
in C but not PHP--when I've needed to get something like that going
with a PHP script, I've used ser2net (which I linked to in an earlier
post) and been quite happy. Maybe you don't even have to do the hard
work yourself (or buy extra hardware to do it for you).


Cheers,

Torben

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



[PHP] How to download and configure php mvc website locally

2009-08-19 Thread Sumit Sharma
Hi,
Please help as I have downloaded a php website for my client which is
developed using model view controller pattern. Now when I am accessing this
site locally it is not showing any thing. Please tell me the what's the
problem

Thanks,
  Sumit Sharma


RE: [PHP] SESSIONS lost sometimes

2009-08-19 Thread Angelo Zanetti


-Original Message-
From: Ben Dunlap [mailto:bdun...@agentintellect.com] 
Sent: 19 August 2009 08:18 PM
To: Angelo Zanetti
Cc: php-general@lists.php.net
Subject: Re: [PHP] SESSIONS lost sometimes

> 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


Hi Ben, 

When the problem happens the $_SESSION is partially empty. It only has the
some of the variables set.

It happens on a certain page only, but the strange thing is that it never
happened before its only happening now. But the code hasn't changed so is it
safe to assume that it's a server issue?

Thanks
Angelo

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