My site has a php page that prints out XML, for some reason though it's being truncated to 8KB in size, I've never encountered this before and all the other pages on the site remain un-truncated.
Where should I start looking for the problem and what could cause it to stop like this?
The site uses the Zend framework and the page in question uses the soap server.
Put this before the section where the output cuts off:
error_reporting(E_ALL);
ini_set('display_errors', 1);
Chances are there is just an error that is not being output. Also make sure your code does not contain the error suppression operator (# symobl) as this is a common cause of hard to detect errors: http://www.php.net/manual/en/language.operators.errorcontrol.php
If my first suggestion fixed your issue then I would suggest that you set up and test error handling correctly so that you will receive all errors in the future as this will save you a lot of time.
I'd expect an error if it was memory but have you tried increasing the memory limit in php.ini?
It could be some memory limit, it could be some arbitrary part of the script that is running at that part of the XML creation.
Check what errors you are getting, see if any errors are suppressed. And if all else fails, post some example code that is running at that 8KB mark.
Related
I am writing an application that submits html forms to a php script. At the end of the php script I have header("Location: finished.html");.
The goal is that once all of the data has been analyzed /submitted to sql etc.. the page would redirect.
My question is is this okay practice? It seems unreliable to simply set the header at the end of the script being that various errors could happen throughout the script.
I don't want the page to simply end up at the php script, and I would like to know if there are errors throughout. I am doing as much error checking as I can.
You can use header() without problems as long as you did not send any response to the client using echo/print and the likes or normal text/html, beware of spaces/newlines before <?php
PHP stops processing once it encounters an error.
PHP will continue processing if it encounters a warning/notice, but if the onscreen error reporting is enabled, the warning generated output will prevent header() from executing as stated by #Simba in the comment.
Using an output buffer requires the server to store the entire output of the PHP in RAM, so if I have a large page, I'll wind up using a fair amount of memory - and the server will also have to wait until the entire page is generated before sending it out, which could cause a small delay. that's right ?
I don't want to know the advantage of using ob_start();. My problem is redirecting and this error: Headers already sent.
So for solving that problem, I used of ob_start(); in the fist of my codes. something like this:
<?php ob_start(); ?>
<?php
// 500 lines of code is here
header(Location: www.example.com/test.php);
?>
<html>
// 1000 lines of code is here
</html>
<?php ob_end_flush(); ?>
Now my problem has been solved, just I want to know everything is ok ? my codes are optimized ? If my requests rise, my site does not delay ?
thanks
The proper solution to the "Headers already sent" problem is described in a previous thread.
Basically, the correct cause of action is to move all of the processing code above any output to the browser. Then simply echo out the results, as needed, in between the HTML code.
Not only will you notice an improvement in the resource usage of the page, but you'll also notice that it will become a whole lot easier to actually read and write the code.
If the output branches are complex enough, which means anything above a very basic script (simple guestbook, etc), a template engine might be well worth the time and effort to look at.
Output buffering is frequently used and I wouldn't worry about this. For example, this SO webpage takes up ~ 64 KiB, meaning 16384 of these pages fit in 1 GiB ram simultaneously.
Probably offtopic, but if you're going to send a Location header, do you even need to execute all the other code? You could just send the header and exit() immediately.
I'm playing with various ajax uploaders. When analyzing their server-side code, I see something like this:
#unlink($_FILES['file']['tmp_name'])
It is either muted one (like above), so does nothing (in my case) or unmuted one, so throws a warning, that access to temporary folder is prohibited (in my case) and breaks execution of a script.
What am I missing? I was always told, that we should not touch temporary files transmited via PHP form. Because this is unnecessary (and somethimes prohibited, like in my case). PHP will do all the cleaning, when script ends -- i.e. remove all uploaded temporary files.
What is the reason in code like above? Is it for the case, when script breaks, PHP is halted with some critical error and thus isn't able to remove temporary files? Or there is another reason?
Edit: It is quite pity, that I found this kind of mistake even in Plupload example code.
As per comments - there's nothing you've missed. Unlinking shouldn't be done by the user-code, such things might not be permitted and can fail due to various reasons.
I'm getting an error showing up in my error logs over and over. I see it in an error log in cpanel as well as in an AW stats report.
The errors look like this:
/my_directory/'%20+%20protocol_host%20+%20'/images/greenthumb.png
/my_directory/'%20+%20protocol_host%20+%20'/images/imgsicon.png
I'm seeing this thousands of times a day.
the legit path in the example above would be something like this:
/my_directory/page.php?id=123454
(i.e www.my_site.com/my_directory/page.php?id=123454)
Any ideas what this protocol_host is referring to and why it would be hitting my error log so often?
My research before posting this question led me to something related to the search indexer on a windows operating system computer, but I can't see the connection.
Thanks in advance as always
I'm with #Shal. Although google gives you some results for 'protocol_host' I don't think that they are related to your problem. I guess it is either an error in your PHP code which generates the links or an erroneous client (or a hacker) is accessing your site
Looking at the error-URLs, it seems like the paths to some images are generated dynamically by concatenating strings; but the quotes are note set correctly.
/my_directory/'%20+%20protocol_host%20+%20'/images/greenthumb.png
without URL encoding is
/my_directory/' + protocol_host + '/images/greenthumb.png
PHP uses . to concatenate strings, but here a + is used. So I would guess that some JavaScript code causes this error.
Check your JS resources!
I would guess, that you are linking some resources relatively without a leading slash.
example:
<img src="images/foo.png" />
usually this leads to urls like http://example.com/images/foo.png instead of http://example.com/my_project/images/foo.png but can have other conseques as well.
This is just a guess though.
Due to many included files create an error like instead showing the contents it only shows blank or one of the files has an error like no comma in the end of the script do not shows an error print like fatal error or syntax error in PHP?
I'm a bit worried cause i working on a site right now that has almost 20+ files to include from different directory.
I separated the files like a file that contains the page function, session functions, image function and other more.
I need some advice from anyone. Experts or not experts I really need to know this....
Sounds like you have error reporting turned off, i am not sure, if this is your question, though ;-). Put
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
at the very beginning of your script if you want to debug and don't want to change php.ini settings. Debugging like this on a production site is for obvious reasons not recommended, though (every visitor can see the error including sensible information, the error might contain).
It does not matter how many includes you have in your application -- 20 are not much, btw. -- you will always get the error together with the information in which line and which file it occured ...