如何停止php执行
我现在搞了个采集的php代码,把网页的数据采集下来保存在桌面,现在测试的时候发现一个问题,在浏览器关闭的情况下,php还在继续执行生成数据,问题来了:如何在关闭浏览器或者点击浏览器上url输入后面的停止按钮使得php代码不再继续执行?
回复讨论(解决方案)
php默认是关闭就停止执行了啊,你用ajax请求php吗?
回复楼上的没有用ajax
直接关闭浏览器就停止了,当前的PHP操作了。
建议从几个角度去查问题:
1.浏览器的进程是否结束
2.Linux的情况,使用不同WEB服务时,配置是否正确,是否存在配置导致浏览器关闭,但是WEB服务的当前进程仍然在执行。
伪进程?
很多人想搞还搞不来呢!
你需要在你的代码中设施并处理可以触及到的终止信号
最近我也发现了这个问题, 浏览器关闭, 程序是会执行的。
但是应该是执行完当前的内容后, 就会停止。
如果你是本地测试, 我一般都直接重启服务。
你要做采集, 建议还是用bin方式来做。
最近我也发现了这个问题, 浏览器关闭, 程序是会执行的。
但是应该是执行完当前的内容后, 就会停止。
如果你是本地测试, 我一般都直接重启服务。
你要做采集, 建议还是用bin方式来做。
bin方式指的是?求指点
set_time_limit();
设置脚本最多执行的时间,是最简单的方法。
呵呵,你虽然关了浏览器,但是程序的指令早就已经发出去了,再他未完成所有的指令之前,假如没有给停止命令(是的是跟底层,服务器有关的指令,不是指管浏览器),之前的未完成的指令会继续执行,知道指令完成或者被迫停止(比如重启服务器,或者重启web服务程序)
加个exit()试试看
嗯,我的采集也出现了这个问题,关闭了浏览器,还一直在下。我的猜想是跟php curl的工作机制有关,具体原因不清楚。
起初我注销电脑都不行,一定是重启。
可能因为是http协议,最后我在进程里关闭浏览器的进程就可以了;另外我觉得可以关闭apache服务应该也可以,没试过。
程序设置了最大执行时间很长,程序里面用了sleep主要防止采集的太快封ip,不知道和这个有没关系。
程序设置了最大执行时间很长,程序里面用了sleep主要防止采集的太快封ip,不知道和这个有没关系。 目测和这个没有关系,php curl是可以支持代理的。
跟这个没关系,但跟你的程序写法有关系,由于并没有看到你的程序,所以也不能明确的说
一般的说:
当关闭浏览器,程序会终止(php 还专门设有函数来改变这个行为),是有条件的
这个条件就是程序必须有输出
php 只在有输出时才去检查到用户的连接是否断开
先在任务管理器确认浏览器进程是否关闭了再谈更高深的问题吧
我关浏览器通常都要等几分钟进程才结束,机器年代久远……
还是没找到解决办法,只有重启apache才能终止。
就是php的命令行方式, 而且最好是在Linux下面使用, 稳定。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
