php requests

lozina

Lifer
Sep 10, 2001
11,709
8
81
if I write a php script that basically has an infinite loop, when does it actually terminate by default configuration? And how do I configure this?

I would like to write a script that acts almost like an app itself. It will be an infinite loop because every x seconds it is to do some task and then sleep(). So I'd like for this to keep going potentially for days without stopping - until I set a certain condition which it detects and stops by itself.

Is this possible to do with php and if so what configurations would I need to make so these "threads" are never killed by the web server?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
You won't be able to do this in any decent webserver without significantly affecting the overall performance of the server. If you have long running tasks, they are far better to be performed 'offline'. You would have to alter the timeout value of the scripting engine, and that brings up a whole host of performance and denial of service scenarios you don't really want to get into.

You can still write the code in php, just use the command line interpreter to execute the code on your server via a cron job or some other manual means. However, I think with some more details we might be able to help you come up with a better solution as right now this sounds like a duct tape hack.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
13
81
www.markbetz.net
Yeah, as Crusty says it's not about the language; it's about the context. A web server is a request/response daemon. When you receive a request you should process and return a result as quickly as possible, thus returning your thread to the worker pool to process another request.

You could spawn a separate thread and run that as long as you like, but it might adversely affect the web server's resource management, and might impact other users of the server. A more robust solution is to have a separate process that does any long-term heavy lifting, and communicates with the web server through some IPC mechanism (file i/o, database, pipes, web service, etc.)
 

EricMartello

Senior member
Apr 17, 2003
910
0
0
if I write a php script that basically has an infinite loop, when does it actually terminate by default configuration? And how do I configure this?

I would like to write a script that acts almost like an app itself. It will be an infinite loop because every x seconds it is to do some task and then sleep(). So I'd like for this to keep going potentially for days without stopping - until I set a certain condition which it detects and stops by itself.

Is this possible to do with php and if so what configurations would I need to make so these "threads" are never killed by the web server?

Yes, you can do this, but you must compile PHP with PCNTL, which is process forking for PHP.

What you described is a daemon (not an app), a program that starts and runs until it is killed by the user or another program. Using PCNTL functions you can create a script which starts and stays in in the memory and does whatever you need it to. Whenever it is tasked with doing something, it forks a child process. The child process completes the task and dies...pretty much like any other program would work.

PCNTL requires that you run the php script using the command line interpreter, or that you are using apache with FastCGI or mod_fcgid...but yeah, the command line is better since it is faster than either of those apache interfaces. You cannot execute a php script containing a pcntl function using apache/mod_php since there is no separation between the apache process and the PHP interpreter. Both fastCGI and mod_fcgid are slower than mod_php.

It's loathsome to me that they have not yet made a PHP compiler that is included with the official distro...PHP has a lot more capability than people realize.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
PHP has a lot more capability than people realize.

Anyone that knows anything realizes that any Turing complete language can be coerced into doing anything any other Turing complete language can. The reason people don't use PHP for anything other than websites is that it's a terrible language. It's bad enough that it infected web development; we don't need it elsewhere.
 

EricMartello

Senior member
Apr 17, 2003
910
0
0
Barnaby W. Füi;29969013 said:
Anyone that knows anything realizes that any Turing complete language can be coerced into doing anything any other Turing complete language can. The reason people don't use PHP for anything other than websites is that it's a terrible language. It's bad enough that it infected web development; we don't need it elsewhere.

Yeah, it's badness must have been the driving force behind its widespread adoption...PHP is used to do a lot more than websites although I doubt you would be aware of these things.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Yeah, it's badness must have been the driving force behind its widespread adoption...PHP is used to do a lot more than websites although I doubt you would be aware of these things.

Why are you such an asshole to people with an opinion that doesn't match yours?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Yeah, it's badness must have been the driving force behind its widespread adoption...PHP is used to do a lot more than websites although I doubt you would be aware of these things.

Popularity implies nothing about high quality. If anything, it might imply the opposite.
 

EricMartello

Senior member
Apr 17, 2003
910
0
0
Barnaby W. Füi;29975114 said:
Popularity implies nothing about high quality. If anything, it might imply the opposite.

True, but in the case of PHP its performance capabilities and general ease of use is a major reason behind its popularity...anyway, not only are you wrong in your assessment of PHP, but you are driving this thread off topic. If you have nothing to add to the OP's question then run along.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
True, but in the case of PHP its performance capabilities and general ease of use is a major reason behind its popularity...
What performance capabilities? It's not considerably faster than any of its contempories. Certainly, no one is choosing PHP when performance is the primary concern.

PHP is popular in large part because it has an extremely low barrier to entry. That's also why most PHP programmers, and most PHP code, are terrible.

anyway, not only are you wrong in your assessment of PHP, but you are driving this thread off topic. If you have nothing to add to the OP's question then run along.
Forums suck when no one goes off topic. I don't think anyone appointed you as hall monitor.

PHP was created by a guy who doesn't even like to program and readily admits that he threw PHP together. It's a disaster that inflicts itself upon sensible programmers and scars them for life.
 
Last edited:

EricMartello

Senior member
Apr 17, 2003
910
0
0
Barnaby W. Füi;29975891 said:
What performance capabilities? It's not considerably faster than any of its contempories. Certainly, no one is choosing PHP when performance is the primary concern.

PHP is popular in large part because it has an extremely low barrier to entry. That's also why most PHP programmers, and most PHP code, are terrible.

Ohhhh...ooook...now PHP is slow in addition to being "low quality". Better go take your case to Facebook. Let them know that they shouldn't build the biggest website in the world on a shoddy, low-quality platform like PHP.


Forums suck when no one goes off topic. I don't think anyone appointed you as hall monitor.

PHP was created by a guy who doesn't even like to program and readily admits that he threw PHP together. It's a disaster that inflicts itself upon sensible programmers and scars them for life.

A lot of open source programs have humble origins. Linux used to be "just a kernel" that Linus put together for his own personal use and shared on USENET...and now it's the foundation of a widely used OS.

Personally I don't care what you think of PHP. You're obviously nobody important and if you were, I still wouldn't care. When you develop the perfect replacement for PHP go ahead and let us know.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Ohhhh...ooook...now PHP is slow in addition to being "low quality". Better go take your case to Facebook. Let them know that they shouldn't build the biggest website in the world on a shoddy, low-quality platform like PHP.
I didn't say PHP was slow. I said it's not exceptionally fast. Its performance is not convincing anyone to use it.

You seem oblivious to the fact that Facebook developed their own PHP compiler (HipHop) to improve their PHP performance. I'm sure they're also well aware of the challenges of writing good PHP code. It is possible, but when you achieve it, it's mostly in spite of the language.

You're obviously nobody important and if you were, I still wouldn't care.
You're appealing to authority. It doesn't matter who I am or who you are. What matters is the truth.


When you develop the perfect replacement for PHP go ahead and let us know.
Python, Ruby, and Perl are all much better replacements for PHP. Obviously, nothing is perfect.
 
Last edited:
Oct 27, 2007
17,010
1
0
PHP is an objectively bad language. Anyone who doesn't know this should GTFO of a programming forum until they learn a little something about the craft. EricMartello, you are wrong. I'm not going to go into why you are wrong, because you've also proven to be arrogant and hard-headed in your wrongness. You believe that you're smart, which is what's really perverse about this.

In the modern world the stupid are cocksure while the intelligent are full of doubt.
Think about that for a minute.
 

ScottSwing

Banned
Jun 13, 2010
447
0
0
Change the value of max_execution_time in your php.ini file. Get too high and you'll have to worry about memory leaks and other performance issues as mentioned.

What exactly does the script do that you want to run?
 

ScottSwing

Banned
Jun 13, 2010
447
0
0
Barnaby W. Füi;29969013 said:
Anyone that knows anything realizes that any Turing complete language can be coerced into doing anything any other Turing complete language can. The reason people don't use PHP for anything other than websites is that it's a terrible language. It's bad enough that it infected web development; we don't need it elsewhere.

Right, why do people even bother making new programming languages? How many are we up to now? Seven?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Right, why do people even bother making new programming languages? How many are we up to now? Seven?

You might want to read about the concept of Turing completeness. It means that any Turing-complete language can eventually compute anything any other Turing-complete language can. It does not mean that languages don't have huge differences in productivity or pleasantness, or that people should stop inventing new languages. You are putting words in my mouth.

EricMartello said that PHP had impressive "capabilities", and I think that's pretty much nonsense. The only thing PHP is particularly good at is getting people started writing code quickly. Unfortunately, that, combined with its numerous bad qualities, results in code bases that are usually a huge mess by the time a real programmer has to come in to rescue the project.
 
Last edited:

EricMartello

Senior member
Apr 17, 2003
910
0
0
Barnaby W. Füi;29976480 said:
I didn't say PHP was slow. I said it's not exceptionally fast. Its performance is not convincing anyone to use it.

Most scripting languages are not known for performance, that is why there are other alternatives when performance is a main consideration. You did not really say anything, and you certainly did not back up any of your statements with examples.

You seem oblivious to the fact that Facebook developed their own PHP compiler (HipHop) to improve their PHP performance. I'm sure they're also well aware of the challenges of writing good PHP code. It is possible, but when you achieve it, it's mostly in spite of the language.

How am I oblivious to that? I'm well aware of hiphop but that doesn't change the fact they they're using PHP when they could have migrated to a "faster, more perfect" platform that you have yet to name.

You're appealing to authority. It doesn't matter who I am or who you are. What matters is the truth.

And yet you have not provide any truth, only weakly constructed criticisms. You're not going to change anyone's mind with what you said...like I said, take your case to Facebook or if not them them have a talk with Yahoo...they're also using PHP.

Python, Ruby, and Perl are all much better replacements for PHP. Obviously, nothing is perfect.

LOL you're a moron.

Barnaby W. Füi;29978442 said:
You might want to read about the concept of Turing completeness. It means that any Turing-complete language can eventually compute anything any other Turing-complete language can. It does not mean that languages don't have huge differences in productivity or pleasantness, or that people should stop inventing new languages. You are putting words in my mouth.

Yes, this confirms that you are a moron. You see there is this thing called CAPITALISM that is the driving force behind the various languages...and aside from that, personal preferences. The fact that you can compute 1+1 in various languages means nothing. There are other elements that affect the performance of the language, as well as licensing issues that make it viable or not.

EricMartello said that PHP had impressive "capabilities", and I think that's pretty much nonsense. The only thing PHP is particularly good at is getting people started writing code quickly. Unfortunately, that, combined with its numerous bad qualities, results in code bases that are usually a huge mess by the time a real programmer has to come in to rescue the project.

This shows that you have very little understanding of PHP or its capabilities in addition to being a fudgepacker. You're "knowledge" is whatever you can parrot from wikipedia/google...yes, another one of those idiots that the internet has enabled to make believe they're smart.

Go ahead and use your superior alternatives to PHP...oh wait...nobody cares...

PHP is an objectively bad language. Anyone who doesn't know this should GTFO of a programming forum until they learn a little something about the craft. EricMartello, you are wrong. I'm not going to go into why you are wrong, because you've also proven to be arrogant and hard-headed in your wrongness. You believe that you're smart, which is what's really perverse about this.

Objectively bad? Quantifying it with the word "objectively" makes worser huh? Yet neither you nor the other cockgobbler have been able explain why...I'm sure when Wikipedia tells you why, you will know...

PHP does what it's designed to do and a lot more. For a scripting language it is very versatile and its license makes it a viable option for private and commercial use alike.

As I said before, people spending a lot of money have decided to use PHP as a platform, and the massive community behind it constantly improves it. It's not as old as Perl, nor is it the same type of language as python or ruby....but it is what it is, and it's very good at what it does.

So yes, you can follow me from thread to thread if you enjoy being consistently wrong, and also being reminded of how stupid you are. That's why I'm here.
 

ScottSwing

Banned
Jun 13, 2010
447
0
0
PHP...is a terrible language. It's bad enough that it infected web development; we don't need it elsewhere.
Terrible language, bad for web development, bad for everything else...
PHP is particularly good at...getting people started writing code quickly.
It's terrible, but it's good at what it's designed to do. You're contradicting yourself.
Barnaby W. Füi;29978442 said:
You might want to read about the concept of Turing completeness. It means that any Turing-complete language can eventually compute anything any other Turing-complete language can.
Yeah you keep saying that. Did they just teach you about that in computer science class?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
It's terrible, but it's good at what it's designed to do. You're contradicting yourself.

Unless it's designed to create unmaintainable nightmares, then I'm not contradicting myself. Getting a project started quickly is all fine and well if you're making a simplistic 100 line web script, but in real life, code always grows larger than you thought it would, and with PHP, that means that you usually get painted in a corner and are stuck using this awful language to develop and maintain a large application.
 

ScottSwing

Banned
Jun 13, 2010
447
0
0
Barnaby W. Füi;29978822 said:
Getting a project started quickly is all fine and well if you're making a simplistic 100 line web script
Which is the majority of the internet.
but in real life, code always grows larger than you thought it would, and with PHP, that means that you usually get painted in a corner and are stuck using this awful language to develop and maintain a large application.
You can't use your immense programming knowledge to rewrite 100 lines of code?
 

EricMartello

Senior member
Apr 17, 2003
910
0
0
Barnaby W. Füi;29978822 said:
Unless it's designed to create unmaintainable nightmares, then I'm not contradicting myself. Getting a project started quickly is all fine and well if you're making a simplistic 100 line web script, but in real life, code always grows larger than you thought it would, and with PHP, that means that you usually get painted in a corner and are stuck using this awful language to develop and maintain a large application.

So now you're blaming your lack of organizational skills on PHP. I have created and managed large PHP-based apps from scratch in addition to contributing to some "little known" open source projects such as OSCommerce, PHPBB and a PHP-based bitorrent. Each of these projects is large, and obviously the open source efforts have many people working on them. Problems maintaining the code? No, not really. This is where coding conventions come into play...this is where the lead developer tells everyone else how things are going to be done so everyone has am mutual understanding, and to enable a sense of uniformity in the code. There are also tools like CVS and subversion that make managing code iterations quite simple for the developers involved.

You don't know enough about anything to say whether it's good or bad...you're clearly a clueless noob who quickly meets the end of his wit. Why don't you scurry on back to ATOT where your general lack of intelligence comes across as entertaining.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
and you certainly did not back up any of your statements with examples.
And you did? I'm not writing a research paper and I'm not going to spend an hour hunting down references for a web forum post. And you proclaim to be good at searching Google and Wikipedia, so knock yourself out.



How am I oblivious to that? I'm well aware of hiphop but that doesn't change the fact they they're using PHP when they could have migrated to a "faster, more perfect" platform that you have yet to name.
How would you propose they migrate millions of lines of code? You don't migrate that. To a large extent, you're stuck with it. As far as I know, they are writing some new code in other languages.

like I said, take your case to Facebook or if not them them have a talk with Yahoo...they're also using PHP.
I don't know why you think it's convincing to drop names of big companies like that. Big companies make just as terrible of decisions as anyone else, and particularly with large code bases, inertia is a problem that locks you into whatever you decided many years ago, however flawed that decision may have been.



LOL you're a moron.

Yes, this confirms that you are a moron.

Good one.

You see there is this thing called CAPITALISM that is the driving force behind the various languages...and aside from that, personal preferences. The fact that you can compute 1+1 in various languages means nothing. There are other elements that affect the performance of the language, as well as licensing issues that make it viable or not.
Sure, everyone realizes this stuff. My point was that PHP has no compelling features other than being easy for newbies to get started with. Being easy for newbies to get started with has little relation with being a high quality language that is suitable for maintaining large applications over the years, and in fact probably negatively impacts it. (In PHP's case it certainly does)

This shows that you have very little understanding of PHP or its capabilities in addition to being a fudgepacker.

You're such a big baby. Can't you discuss something without talking like an immature brat?

You're "knowledge" is whatever you can parrot from wikipedia/google...yes, another one of those idiots that the internet has enabled to make believe they're smart.

Okay. Again, a really convincing argument. I know nothing and just search the web to respond to people on web forums.

Go ahead and use your superior alternatives to PHP...oh wait...nobody cares...
Sure they care. Lots of other people hate PHP and love using better languages.

Objectively bad? Quantifying it with the word "objectively" makes worser huh? Yet neither you nor the other cockgobbler have been able explain why...I'm sure when Wikipedia tells you why, you will know....

Clearly you can't behave like a grown up. Maybe you should troll somewhere else.
 

GaryJohnson

Senior member
Jun 2, 2006
940
0
0
Anyone who doesn't know this should GTFO of a programming forum until they learn a little something about the craft.

Isn't a programming forum somewhere someone would go to learn a little something about programming? I think that's what the OP was trying to do before his thread got hijacked.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |