Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a question regarding why via

php -q -f /home/user/public_html/file.php (this script contain a small script that create a file).

file.php content:

$csvFile = 'http://example.com/file.csv';


function readCSV($csvFile){
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle) !== FALSE) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    }
    fclose($file_handle);
    return $line_of_text;
}

$csv = readCSV($csvFile);

$xml = new SimpleXMLElement('<data/>');

foreach ($csv as $_item){
            $itm = $xml->addChild('produs');
            $itm->addAttribute('city', $_item[0]);
            $itm->addAttribute('street', $_item[2]);
            $itm->addAttribute('number', $_item[3]);
            $itm->addAttribute('user', '0');
        }

$dom = new DOMDocument();
$dom->loadXML($xml->asXML());
$dom->formatOutput = true;
$formattedXML = $dom->saveXML();

$xmlFilePath = 'file.xml';
//i solved the issue with '/home/path/to/be/stored/'
$fp = fopen($xmlFilePath,'w+');
fwrite($fp, $formattedXML);
fclose($fp);

The issue is that on execute the command the file is not created, but on access on web via http it is created.

There is no error, it just say that the file has been created but is not.

Centos 6 - Minimal Server Nginx, PHP-FPM. User www-data and root, both does the same.

Any help is appreciated.

share|improve this question
    
Check your audit.log for relevant SELinux AVC denied messages. –  Iain Jun 3 at 6:46
    
You need to do error checking. Don't just blindly assume that functions will succeed. –  Michael Hampton Jun 3 at 10:01

1 Answer 1

most likely, this is a permission problem where when the process is executed via the php-fpm, it can write to the location in question, but when run by your user account, the location is not writable.

to see the full details of what is happening with the script, try running it under strace

strace php -q -f /home/user/public_html/file.php

share|improve this answer
    
well, the issue is that if i execute as it on shell, php -q /home/user/public_html/file.php i see that the file is created, but on put the command on a sh script it doesnt create :( –  Dario Jun 3 at 6:43
    
Can be an issue when the file name is specified without folder ? –  Dario Jun 3 at 6:47
    
there is no "put" command in bash/sh, unless you write the function yourself. edit the question and give more details in order to get more help. it is not clear what you are doing. –  nandoP Jun 3 at 6:47
    
the issue was that i have declared only the file name without folder, strange, because in other servers it work without declare the path. –  Dario Jun 3 at 7:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.