admin管理员组

文章数量:1122832

Let's say I have a php file named get_data.php Now I am running this file in cronjob passing a parameter like php get_data.php 1. Now if there is 25 parameters then I have to run this file 25 times like

0 * * * * PHP get_data.php 1
0 * * * * PHP get_data.php 2
0 * * * * PHP get_data.php 3
0 * * * * PHP get_data.php 4
.
.
.
0 * * * * PHP get_data.php 25

Now I am looking for a solution to manage this easily. I want to make file all.php and running it on cronjob. in all.php I want to run all the get_data.php file.

There are some ways to do this but it doesn't work in my case.

  1. Include all get_data.php files in the all.php file. This will run get_data.php sequentially, but I want to run it parallelly.

  2. call all get_data.php files parallelly with curl_multi but that will use my webserver and it may cause a timeout issue. I want to run these files in cli

Sorry if I don't make the question clear.

Let's say I have a php file named get_data.php Now I am running this file in cronjob passing a parameter like php get_data.php 1. Now if there is 25 parameters then I have to run this file 25 times like

0 * * * * PHP get_data.php 1
0 * * * * PHP get_data.php 2
0 * * * * PHP get_data.php 3
0 * * * * PHP get_data.php 4
.
.
.
0 * * * * PHP get_data.php 25

Now I am looking for a solution to manage this easily. I want to make file all.php and running it on cronjob. in all.php I want to run all the get_data.php file.

There are some ways to do this but it doesn't work in my case.

  1. Include all get_data.php files in the all.php file. This will run get_data.php sequentially, but I want to run it parallelly.

  2. call all get_data.php files parallelly with curl_multi but that will use my webserver and it may cause a timeout issue. I want to run these files in cli

Sorry if I don't make the question clear.

Share Improve this question edited Nov 22, 2024 at 5:49 DarkBee 15.8k8 gold badges69 silver badges110 bronze badges asked Nov 22, 2024 at 4:28 Md. Sahadat HossainMd. Sahadat Hossain 3,2364 gold badges34 silver badges56 bronze badges 1
  • 1 You can make cron run ie bssh script that then starts multiple php scripts ie with nohup or &. Or you can use pcntl_fork() (see this then). – Marcin Orlowski Commented Nov 22, 2024 at 4:43
Add a comment  | 

1 Answer 1

Reset to default 1

For such a simple command, you can use one line of bash command:

0 * * * *  bash -c "for i in {1..25}; do PHP get_data.php \$i & done"

本文标签: phpHow to run multiple files from one file in parallelStack Overflow