Apache PHP Server with time-consuming processes

Asked

Viewed 1,766 times

1

I have an application that has some lengthy requests, I wonder if PHP how to set php to work with the best possible configuration, I wonder if while it makes this lengthy request I could make a new request or it gets stuck?

  • 1

    It must have something to do with the logic of your code. Show us the script that makes this "time consuming request", please.

  • The script is to be even lengthy

  • 1

    You can run a profile (like Xdebug) and check where the bottleneck is, then you can [Edit] the question with the source code.

  • 2

    If it is time-consuming, it should probably be executed locally, directly from the command line, without going through Apache, or with an scheduled task, or with an infinite loop and a Sleep between cycles. But without more details in the question, everything is kick.

  • 1

    Remember that you can [Dit] the question by adding more details, to the point where the question becomes more specific. Just be careful not to misrepresent the initial doubt to the point of completely invalidating the existing answers.

2 answers

1

There is no such restriction, but it depends on your SO and of hardware. How your configuration uses PHP as a module of Apache, is the Apache who is managing these connections, and he already manages the multiple requests.

The concept of multitarefa is not related to the PHP, but with the operating system and with the hardware. Multitasking, for example, requires multiple core processor and SO that can use these cores for multiple simultaneous runs.

The PHP runs to the configured memory limit. If your running script occupies all the memory stored there the system creates a "run queue". Things like the ability of the connection link can also influence the result. These problems (latency, packet loss, etc.) are usually solved with the operator, and may be related to the contracted band limit.

In the PHP, the general settings are made in php.ini, and the change of the memory limit is made in Directive memory_limit. Things like response time (max_execution_time) and size limit p/ upload (upload_max_filesize), (max_input_time) also influence the execution of scripts.

  • I understood, but which configuration I change to let php use more memory and link?

  • So from what I understand, while the big script runs the other pages should normally open it is this?

1


Web server (Apache) does not crash while executing a request.

Apache has a default configuration that can handle multiple simultaneous requests. It can do this by starting threads within each process and starting new processes.

PHP, which is run by Apache, has many settings and maybe you should explore each one to understand which ones can help you with your case. The "best" setup is hard to know because each project has a different need.

However, like any program running on the server, depending on what it is doing it can "lock" that process and a new request will be met by another process. In Apache, as there can be several processes running, one time-consuming process will not prevent another one from running, but because the machine is one, depending on the type of operation you are doing, it will not be able to respond to the requests in a timely manner. For example, if you have Apache and Mysql installed on the same machine and your PHP runs a complex query or does time-consuming disk operations, the whole machine will be too loaded for Apache or any other process to run properly.

Ideally, you design your application so that it doesn’t run time-consuming processes inside the Web server. In cases where time-consuming processes exist and cannot be circumvented, your PHP script should pass to another application within the server this long task and the web server would be released. That way, on the client side, you would have some page where you could monitor the progress of this long process, freeing the Web server to do its service, which is to meet the requests of other clients. The other way is to improve server machine configuration or try to optimize your SQL script/queries it executes to return to requests faster.

In the end there is no answer of best possible configuration. It all depends on you understand the settings and adjust for your case. It is interesting to investigate also the reason for the lengthy process.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.