I have a strange php issue.
I have a custom front-end post submission form for WordPress. It most of the time but the other times it seemingly at random doesn't work.
My PHP error log spits out the following:
PHP Warning: copy(): Filename cannot be empty in /home/y567889/public_html/wp-content/themes/colormag/inc/front_deck.php on line 1071
PHP Warning: file_get_contents(https://ygoprodeck.com/pics/Trinity World Chalice-deck-14461.png): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/y567889/public_html/wp-content/themes/colormag/inc/front_deck.php on line 1025
PHP Warning: unlink(/home/y567889/public_html/pics/Trinity World Chalice-deck-14461.png): No such file or directory in /home/y567889/public_html/wp-content/themes/colormag/inc/front_deck.php on line 172
So in theory, a user could submit 10 posts. Sometimes 2 of those posts would generate with errors (missing featured image etc etc) with the above error in the php log.
What I have tried:
Changed copy() to move_uploaded_file() with no joy.
Changed permissions on the "pics" folder to 775.
It occurs to one of my users in particular. It happens him with every post he attempts to upload. Generating a new WP account fixes this for him (although it still fails occasionally as per usual).
Because the error starts at line 1017 I'll show what the code is for that:
function moveYdktoDeck($ydkId,$postid){
$ydkUrl = wp_get_attachment_url( $ydkId );
$newfile = $_SERVER['DOCUMENT_ROOT'].'/UploadedDecks/3/'.$postid.'.ydk';
copy($ydkUrl, $newfile)
}
Function wp_get_attachment_url can return false. Check that before you use it in copy function.
I have some issue with my production deployment of Symfony2,
I've tried many solutions, but none have worked.
I randomly have this error when accessing my symfony application on production environment:
( ! ) Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: simplexml_load_file(): I/O warning : failed to load external entity "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml"' in /home/user/symfony/app/bootstrap.php.cache on line 2998
( ! ) Symfony\Component\Debug\Exception\ContextErrorException: Warning: simplexml_load_file(): I/O warning : failed to load external entity "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml" in /home/user/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 736
Call Stack
# Time Memory Function Location
1 0.0000 262880 {main}( ) ../app_dev.php:0
2 0.0015 572736 Symfony\Component\HttpKernel\Kernel->handle( ) ../app_dev.php:79
3 0.1342 4023952 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( ) ../bootstrap.php.cache:2376
( ! ) LogicException: Request stack is empty in /home/user/symfony/app/bootstrap.php.cache on line 2998
Call Stack
# Time Memory Function Location
1 0.3330 7110120 Symfony\Component\Debug\ErrorHandler->handleException( ) ../classes.php:0
2 0.3331 7119696 Symfony\Component\Debug\ErrorHandler->handleException( ) ../classes.php:1939
I've tried to upgrade my php version (I was in php 5.4.x and now in 5.6.4),
I've tried to upgrade lixml2 version (i am in 2.8.0 now, but i already tried to upgrade in 2.9.3)
I've constated that the version of libxml used in php is always 2.8.0, but, I haven't found the way to change this ,
I've tried to set the all directory of symfony in chmod 777
My server is a debian 7.5 server.
Maybe someone who knows this error can help me
Here is some links to differents question related to this one:
Random Error, FOSUserBundle Error and Service error
I didn't post in them because they're all outdated
[EDIT]
I found a quick fix, but it's in vendors, so it will be overrided in the first update of the doctrine update:
QuickFix in XmlDriver.php Line 737
$xmlElement = #simplexml_load_file($file);
if(!$xmlElement){
$xmlData = file_get_contents($file);
$xmlElement = simplexml_load_string($xmlData);
}
We got this error after we started using libxml_disable_entity_loader(true); in our code. That code is vital in preventing XXE -attacks(more info of that in here). If you don't have that in your code, it could be that you have installed/updated a bundle which has that line of code in use. Note that libxml_disable_entity_loader() is not thread safe, so if there is one piece of code on one thread that executes that line, everything on that server now has that enabled throughout the process.
The FOS-bundle seems to use xml-definitions, that in return have external entities in them. Nothing major though, but that code prevents the FOS-bundles methods from using those files correctly.
Luckily, our service got that error only in one place, and the fix was obvious:
Add a libxml_disable_entity_loader(false); before executing that piece of code where the error comes from, and add libxml_disable_entity_loader(true); right after that piece of code.
This way the user bundle could load the xml:s it needed, but security is not compromised.
Example:
libxml_disable_entity_loader(false);
$user = $query->getOneOrNullResult(); // This generates an error if entity loader is disabled
libxml_disable_entity_loader(true);
The error mentioned usually happens when the xml file does not exists.
You can try check if the file really exists after try to load:
if (file_exists($file)) {
$xmlElement = #simplexml_load_file($file);
}
I tried to simulate the error locally running php interactively, the results are in down:
php > simplexml_load_file('test.xml');
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "test.xml" in php shell code on line 1
php >
Note, the error above is the same that you mentioned on the question. So, the first try is use the file_exists() function to check if the file really exists after try to load it. The next step is check if the current path - using getcwd() - and the path of the file are pointing correctly to the file.
I created a file called test.xml on /tmp folder:
<test>
<worked>
</worked>
</test>
Called the interactive mode on php:
$ php -a
Interactive mode enabled
So, checked my local directory:
php > echo getcwd();
/tmp
And, tried to load the file:
php > $data = simplexml_load_file('test.xml');
php > var_dump($data);
object(SimpleXMLElement)#1 (1) {
["worked"]=>
object(SimpleXMLElement)#2 (1) {
[0]=>
string(2) "
"
}
}
Note: that worked correctly. So, probably, your file does not exists or the path are incorrect. The path considers the current path /tmp plus, the file indicated on the function call test.txt, or equals to call the /tmp/test.txt file.
In my case, the problem on new hosting was:
allow_url_fopen
was disabled (any simplexml_load_file() or file_get_contents() returned false).
Solution: enable allow_url_fopen.
There are some solutions given:
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1062
https://github.com/symfony/symfony/issues/7291
I'm processing a large number of zips and can't track down an error.
The problem is that after the import script runs for a while it suddenly stops with an error at a random zip file. If I try to re-run the script for only that single file, it works (so I exclude that the zip is faulty).
The process is like this: Open zip archive, read content, copy images from the zip, close archive.
I have two questions:
1. Why doesn't PHP simply return false instead of throwing the following error:
PHP Error[2]: copy(zip:///path/to/file/319759.zip#nwh1131_1.jpg): failed to open stream: operation failed
Any ideas what the cause can be? Maybe something with the filesystem? (Server is running on Debian 7 wheezy)
Thanks
I'm trying to check when the file on external server was edited last time.
The function filemtime() doesn't work and throws an exception.
Warning: filemtime() [function.filemtime]: stat failed for
http://examplesite.com/export/export.php?username=***&passwd=***&fileType=xml
I think the problem is in the link, because it's not a direct link to the file but to a php script. Does anybody knows how to get around it and get filetime without downloading that file?
I have a PHP script which reads from an xml file to generate a table. The first thing it does is check to make sure the file exists.
$path = getcwd();
if(file_exists($path.'\inc\php\kbs.xml')){
$kbs = simplexml_load_file($path.'\inc\php\kbs.xml');
} else {
echo "Error: No KB file found";
}
For some reason, intermittently, it doesn't find the file. I've tried removing the file_exists check all together (since I know the file does exist) but it still doesn't load the file at times. I can refresh the page and 7 times out of 10 it doesn't load, but sometimes it does.
I never ran into this problem during development, but once it went production (being used by maybe 200 users now) it started happening.
How do I go about troubleshooting this? (PHP 5.2.14 running on IIS)
EDIT: Error logs give me the following messages when it fails:
Notice: Undefined variable: kbs in <the path> on line 16
Notice: Trying to get property of non-object in <the path> on line 16
Warning: Invalid argument supplied for foreach() in <the path> on line 16
line 16 is the first time the variable $kbs is accessed. Obviously $kbs isn't set if the file isn't found.
Please use the absolute path, relative path make things a mess.
Is the location relative to PHP? Do permissions allow the web server to see it?