G
G
Gangg2018-04-08 19:21:07
PHP
Gangg, 2018-04-08 19:21:07

How to run a script in parallel by different users?

I have a php script that parses certain information from one site and places it on another. In the folder with the script there are other folders and files where he writes certain information, deletes and creates files. cleans folders, etc.
Now I run this script myself locally on OpenServer, everything works.
But I want to throw it on hosting. And add an authorization system to it. So that several users can use this script.
How can I make each individual user run their own copy of the script? And so that each such copy works with its own separate directory for working files? Since each user will have unique information for parsing. And you need that for each copy of the running script, there was its own working folder with files.
So that it does NOT happen that each user runs his own copy of the script, but at the same time the folders and files that are needed for the script to work remain common to all copies of the script.
At least tell me which way to dig? In general, I have no idea from which side to approach and with what request to start googling this topic.
Thanks in advance for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
profaller, 2018-04-08
@profaller

You make a front script that performs authorization, etc. This script launches a worker for each user (your working script that does something there). More or less like this:

$command = 'nohup php my_super_script.php --dir_param=/my_work_dir/  > /dev/null 2>&1 & echo $!';
exec($command, $output);
$pid = (int)$output[0];

You save pid with a binding to the user (a file or in a DB, it already at your discretion). When a user logs on to this pid, you look for the process, if you do not find it, you start it again.
Here is a small class for working with external processes - https://gist.github.com/profaller/f0301eb5d67a6b79...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question