php 脚本是否可以在某个点停止并从之前恢复执行?
我不知道这是否可以使用 php 来完成,但如果可以的话,这对我来说会很棒,而且 php 非常强大,所以我认为这是可能的,但我只是不知道如何实现。
我知道 php 文件是从上到下执行的,但我想知道是否有一种方法可以在某个时刻停止执行,然后在稍后恢复它,或者是否有一种方法可以到达它的某个部分然后从之前的部分或类似的部分恢复?
我知道如何做到这一点,如果我只是将每个单独的代码块放在一个单独的 php 文件中,这样它就会停止,因为它到达了文件的末尾,如果发生某些事情,它将从另一个文件恢复,所以它几乎同样的事情,但我想制作一个 php 脚本,其行为如下但包含在 1 个 php 文件中。
我不需要代码示例,我只需要在正确的方向上点头,比如一些函数名称或可能有助于实现此目的的东西。
i don't know if this can be done using php but it would be awesome for me if it did and php is pretty powerful so i think it is possible and i just can't figure out how.
i know that a php file is executed from top to bottom but i would like to know if there is a way of stopping the execution at some point to then resume it on a later occasion or is there a way of reaching a certain part of it and then resuming from a part that is before it or something like that?
i know how to make this if i simply put each individual block of code on a separate php file, in this way it will stop because it reached the end of the file and if something happens it will resume from another file so it makes pretty much the same thing, but i would like to make a php script that would behave like this but contained in 1 php file.
i don't need code examples i just need a nod in the right direction, like, some function names or something that could be useful to serve this purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试根据用户输入执行操作,您可能应该:
假设您正在执行#1,那么拥有一个特定的 GET 参数来指定您在交互中所处的“步骤”并不那么困难 - 例如,假设您有一个
"AB或C<用户输入>D或E”
。您可以有一个如下所示的 URL 方案:其中所提供的页面上的链接/Javascript/任何内容都允许选择接下来加载哪个页面。您的 PHP 文件将如下所示:
您还可以简单地将这些步骤拆分为不同的 PHP 文件。哪种方法最好可能取决于不同选项之间共享多少功能以及有多少不同 - 如果共享大量功能,则单个文件可能会更容易;如果大多数不同,单独的文件可能更简单。
If you're trying to do things based on user input, you should probably either:
Assuming you're doing #1, it's not all that hard to have a particular GET parameter that specifies what "step" you're on in the interaction - for instance, say you have a sequence of
"A <user input> B or C <user input> D or E"
. You could have a URL scheme that looks like this:where the links/Javascript/whatever on the served pages allow choosing which page loads next. Your PHP file would look something like this:
You could also simply split the steps up into different PHP files. Which approach would be best probably depends on how much functionality is shared between the different options, and how much is different - if lots is shared, a single file might be easier; if most is different, separate files are probably simpler.