简体   繁体   English

是什么导致php脚本无故停止?

[英]What would cause a php script to just stop without reason?

I'm using class.upload.php to upload images to a page. 我正在使用class.upload.php将图像上传到页面。 It seems a script that previously worked is now basically stopping part way through without any errors. 似乎以前可以运行的脚本现在基本上已停止运行,而没有任何错误。 At each line in the script, I'm echoing a number so I can get an idea at which point it stops, ie: 在脚本的每一行,我都在回显一个数字,这样我可以知道它在哪一点停止,即:

// save uploaded image with a new name
$foo->file_new_name_body = $image_name;
$foo->Process($save_directory);

if ($foo->processed) {
echo 'original image copied 1';
} else {
echo 'error 1: ' . $foo->error;
}

echo '1';    $foo->file_new_name_body = $image_name . '_medium';


echo '2';    $foo->image_resize = true;


echo '3';    $foo->image_convert = jpg;


echo '4';    $foo->image_x = 300;


echo '5';    $foo->image_ratio_y = true;


echo '6';    $foo->file_overwrite = true;


echo '7';    $foo->Process($save_directory);


echo '8';

if ($foo->processed) {
echo 'original image copied';
} else {
echo 'error 2: ' . $foo->error;
}

Output: 输出:

original image copied 1
1
2
3
4
5
6
7

I have no way to explain it. 我没有办法解释。 No errors. 没有错误。 No feedback. 没有反馈。 No further code after echo '7'; 回显“ 7”后没有其他代码; is executed. 被执行。 What is going on? 到底是怎么回事? How can I debug? 我该如何调试?

What would be causing this kind of behaviour? 是什么导致这种行为?

Edit I was able to fix the issue simply by changing the file being uploaded. 编辑我仅通过更改要上传的文件即可解决此问题。 It was 2000px wide and when I saved it as a smaller 800px image it completed the process. 它的宽度为2000px,当我将其保存为较小的800px图像时,它完成了该过程。

I changed the memory as suggested to 40m, however this still doesn't let me process a 2000px wide image which doesn't really make much sense to me. 我按照建议将内存更改为40m,但是这仍然不能让我处理2000px宽的图像,这对我来说实际上没有多大意义。 How much memory is needed to deal with files these sizes? 处理这些大小的文件需要多少内存?

Well, I'm no rocket scientist (a) but it seems to me that the most likely cause is that you're not exiting from the call to $foo->Process($save_directory) . 好吧,我不是火箭科学家(a),但在我看来,最可能的原因是您没有退出对$foo->Process($save_directory)的调用。

You probably need to debug that little beast to find out the reason why. 您可能需要调试那只小动物,以找出原因。

First step would be to output $save_directory and $image_name to see what they contain. 第一步是输出$save_directory$image_name来查看它们包含的内容。

Second, I would comment out all those flag setting statements and see if it works with just the copy. 其次,我将所有这些标志设置语句注释掉,看看它是否仅适用于副本。 Then add them back in one at a time until it starts failing again. 然后一次将它们重新添加一次,直到再次开始失败。

It may be that there's either a bug in the conversion code or something wrong with the uploaded image file which causes it to hang. 可能是转换代码中有错误,或者上载的图像文件有问题,导致其挂起。 If the latter, perhaps another (simpler) image file may work - it's worth checking. 如果是后者,也许另一个(更简单)的图像文件可能会起作用-值得检查。

It's no surprise that it would hang at that point, since all the other statement are simply setting up flags for the process call. 到那时它会挂起也就不足为奇了,因为所有其他语句只是为process调用设置了标志。

And, as a last resort, you have access to the source . 并且,作为最后的选择,您可以访问 You can simply make your own copy of it (if you don't already have one) and insert debug statements into that to see where it's stopping. 您可以简单地自己制作一个副本(如果您还没有),然后在其中插入调试语句以查看它的停止位置。

The code for process is actually quite logically laid out. 实际上,用于process的代码在逻辑上布局合理。 It appears to be a succession of blocks of the form: 它似乎是一系列形式的块:

if ($this->processed) {
    # Attempt to do next stage, setting
    #   $this->processed to false if there's a problem.
}

So you could just insert an echo statement before each block to find out which block is causing the problem, then start inserting more debug statements within that block until you narrow it down to the actual line. 所以,你可以只插入一个echo语句每个块之前找出哪些块是造成问题,然后开始直到它缩小到实际的行块插入更多的调试语句。

You may also want to look at the FAQ , especially the bit that states upping the PHP memory limits may assist with larger images. 您可能还需要查看FAQ ,特别是指出提高PHP内存限制的位可能有助于获取更大的图像。 There is also the forums but I see you've already started to go down that route :-) 也有论坛,但我看到您已经开始沿着这条路线走 :-)


(a) : What do rocket scientists say in this situation? (a) :在这种情况下,火箭科学家怎么说?

检查您的内存限制,我发现如果碰到了这个限制,PHP可以(确实吗?)不说什么就退出。

在php.ini中设置了什么-例如,这将显示几乎所有错误。

error_reporting = E_ALL & ~E_NOTICE

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

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