D
D
DVoropaev2016-12-11 11:14:14
PHP
DVoropaev, 2016-12-11 11:14:14

How to organize complex calculations on a web server?

I am making a web server. ubuntu, apache, php7. It is required to carry out large calculations on the server side with asymptotics O(n^2), O(n log n), O(n!). Is it the correct approach to write these calculations in C++?
PHP calls the executable, passes data to it, then gets the return result.
How can this be implemented?
What other approaches are there?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OnYourLips, 2016-12-11
@OnYourLips

You need queues.
In PHP, put a task in a queue, and in a handler in a more productive language, but still a convenient language (does Java have any alternatives?), Get tasks and execute.

D
Dimonchik, 2016-12-11
@dimonchik2013

release asynchronously
python, c++, golang, node, java - everything faster than PHP

F
flr, 2016-12-11
@flr

PHP7 speed is not enough for these calculations? If you are sure that it is not, then the main approaches are:
1. Calling the executable file (as already mentioned).
Normal approach. To start, you can safely start with it. Yes, it seems ugly, but is it a task for you to solve or a purely academic interest? This approach stops working if the binary to run is quite heavy and the service is highly loaded. In general, there is the overhead of starting a new process on the system for every HTTP request.
2. Writing a PHP extension that adds a method or class.
From a technical point of view - one of the best options. But from a practical point of view, one of the worst. In addition to keeping the business logic up-to-date, you will also have to keep the extension syntax up-to-date. Also additional time costs for administration.
3. Microservice (daemon) that will accept requests through the task queue or directly.
To me, it's kind of a compromise. On the one hand, there is no cost to start a new process for each request. On the other hand, there is no link to the syntax of the PHP extension. Such a demon can be written not in C, but in something more friendly, for example, Go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question