简体   繁体   English

同时运行两个不同的PHP程序

[英]Run two different PHP programs at the same time

Good afternoon! 下午好!

I'm currently working on a small project. 我目前正在做一个小项目。 I try to make a simple REST api in PHP to control music. 我试图用PHP制作一个简单的REST api来控制音乐。 The idea is that a call to the api executes a server command with the exec function of PHP. 这个想法是,对api的调用使用PHP的exec函数执行服务器命令。 This is already working :) 这已经在工作:)

What I like to do know is to play multiple files after each other, like a playlist. 我想知道的是像播放列表一样依次播放多个文件。 My idea is two different programs. 我的想法是两个不同的程序。 One program that manage a queue with files that must be played and a program that plays the first item in the queue, than the second, etc. While the song is playing the queue should be modified. 一个程序管理一个必须播放文件的队列,另一个程序播放队列中的第一项,而不是第二项,等等。在歌曲播放队列时,应该进行修改。

So may question is: is this even possible? 因此可能的问题是:这是否可能? I there a way to run these programs at the same time? 我有办法同时运行这些程序吗? Or is my way of thinking way to complex and is there a much better and simpler solution? 还是我的思维方式变得复杂,有没有更好,更简单的解决方案?

Thanks for thinking along with me :) 感谢您和我一起思考:)
Niels 尼尔斯

You could : 你可以 :

  1. Make 2 different API calls from your client, 1 for your queue and 1 for your player 从客户端进行2次不同的API调用,其中1次用于队列,1次用于播放器
  2. Create a bash script that launches both processes as daemon using the & char, and make your API call this script 创建一个bash脚本,使用& char将两个进程作为守护程序启动,并使您的API调用此脚本
  3. Trying some async threads in PHP (I did not test yet), doc here and here 在PHP中尝试一些异步线程(我尚未测试), 此处此处的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM