Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

Could you provide guidance on how to deal with these errors in PHP?

Hi Experts

Could you provide guidance on how to deal with these errors in PHP?

User generated image
The the code snippet launched that generates these errors:

   
 <?php
 
 use Symfony\Component\Validator\Constraints\Currency;

class StoreServer extends CMapBaseWS
{
   ...
   function storeEndTransaction($payment_request)
    {
        
        file_put_contents('debug.log', print_r('StoreEndTransaction 001uuu....', true).PHP_EOL, FILE_APPEND);
 
        $dir = "C:\\MAXXING\\MaxxingEngine\\Temp\HTTPServer\\loadToCard\\Burned";
        
        $data = array("ListCoupons" => array());
        
        $files = glob("{$dir}\\*.json");
        
        foreach($files as $file)
        {
          $data["ListCoupons"][] = json_decode(file_get_contents($file),true);
        }

         $jsonfile = json_encode($data);
         
         
         //Aciona a API para a queima
         // Configurar a sessão curl
         $endpoint = 'https://apihub.br.xxx.xxxx.com/mgus-xxx-burn';
        
        
        $curl = curl_init($endpoint);
        
        
        // configurar os dados a serem enviados:
        $data1 = 
             $jsonfile;  // array de objetos com os dados dos cupons com status BURNED (CPF/ xmlEAN/ msxxing_promotion_burn_code_list/ Staus)
        
        
        // confirmar que a resposta foi recebida
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);  // Deve ser POST
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data1); // enviar o array
        
        
        // Configurar os headers
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
          'x-api-key:-api-key:xxxxxxxxxxxxxx',
          'Content-Type: application/json'
        ));
        
        //Executar a requisição e salvar a resposta
        $response = curl_exec($curl);
        
        curl_close($curl);
        
        //var_dump($response);
        
        file_put_contents('debug.log', print_r('Response....', true).PHP_EOL, FILE_APPEND);
        
        file_put_contents('debug.log', print_r($response, true).PHP_EOL, FILE_APPEND);
      
      ...

Open in new window

PHP log error:

[13-Jan-2021 12:33:00 UTC] PHP Warning:  session_start(): open(C:\MAXXING\Php\session\sess_f93bf311a0679beb5050612e50b4c273, O_RDWR) failed: No such file or directory (2) in C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php on line 2
[13-Jan-2021 12:33:00 UTC] PHP Warning:  session_start(): Cannot send session cookie - headers already sent by (output started at C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php:2) in C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php on line 2
[13-Jan-2021 12:33:00 UTC] PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent (output started at C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php:2) in C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php on line 2
[13-Jan-2021 12:33:00 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php:2) in C:\MAXXING\Apache\htdocs\interfaces\application\config\bootstrap.php on line 4
[13-Jan-2021 12:33:19 UTC] PHP Fatal error:  Call to a member function query() on a non-object in C:\MAXXING\Apache\htdocs\interfaces\library\Flux.php on line 1661
[13-Jan-2021 12:33:19 UTC] PHP Warning:  Unknown: open(C:\MAXXING\Php\session\sess_f93bf311a0679beb5050612e50b4c273, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
[13-Jan-2021 12:33:19 UTC] PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\MAXXING\Php\session) in Unknown on line 0

Open in new window

Thanks in advance.
Avatar of David Favor
David Favor
Flag of United States of America image

This is almost surely a permission problem... at least for part of the problem... for session errors...

1) Normally occurs when PHP runs under a gid/uid which has no access to these directories.

Fix: Open permissions on these directories so PHP can read/write data.

2) This can also occur if these directories are missing also.

Fix: Create directories + open permissions on these directories so PHP can read/write data.

3) For headers already sent, this is a bug in the PHP code running.

Fix: Review code + change to only send headers once.

Note: This is a common problem when layering up function libraries, each of which "expect" to handle header generation.

4) For query() call error, most likely something in the PHP logic has failed to correctly create an object, so either a non-object is being returned or a NULL value is being returned.

Fix: Review code + fix PHP to verify code expected to create objects is correct, then raise an error at exact line of failure raising an exception.

Said differently, in your code building objects. Only have 1x exit point. Then at this exit point raise an exception if NULL or non-object is being returned.

This will Fatal out at exactly the point where code fails, rather than downstream, as is the case now.
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eduardo Fuerte

ASKER

Hi

Really, after copied C:\MAXXING\Php-5.3.10-VC10\ session to C:\MAXXING\Php
those errors disapeared...

I copied the other folders from the C:\MAXXING\Php-5.3.10-VC10\  that maybe are important, also.

Then
That other error occured:
<br />
<b>Fatal error</b>:  Uncaught exception 'Exception' with message '&lt;br /&gt;Module PHP missing or inactive : pgsql (postgreSQL)&lt;br /&gt;' 
in C:\MAXXING\Apache\htdocs\MPCM\Web\include\MapConnectDB.php:317


Stack trace:
#0 C:\MAXXING\Apache\htdocs\MPCM\Web\include\MapGlobal.php(300): CMapConnectDB-&gt;__construct(Object(CMapGlobal), '', Object(CMapLogger), false, true, 'database', 1)
#1 C:\MAXXING\Apache\htdocs\MPCM\Web\include.php(1082): CMapGlobal-&gt;CMapGlobal(1)
#2 [internal function]: __autoload('CMapBaseWS')
#3 C:\MAXXING\Apache\htdocs\MPCM\Web\api\ws\5.3\StoreServer.inc.php(28): spl_autoload_call('CMapBaseWS')
#4 C:\MAXXING\Apache\htdocs\MPCM\Web\api\ws\5.3\StoreServer.php(5): include('C:\MAXXING\Apac...')
#5 {main}
  thrown in <b>C:\MAXXING\Apache\htdocs\MPCM\Web\include\MapConnectDB.php</b> on line <b>317</b><br />

Open in new window


Could you give a look?
Well...

I uncomented

extension=php_pgsql.dll

The error now is just that:

<br />
<b>Fatal error</b>:  Class 'SoapClient' not found in <b>C:\MAXXING\Apache\htdocs\MPCM\Web\module\webservices\mapBaseWS.php</b> on line <b>290</b><br />

Open in new window

The SoapClient is provided by the php_soap.dll extension, I believe.
Yes


extension=php_soap.dll


Now finally the curl errors!



<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
   <env:Body>
      <env:Fault>
         <env:Code>
            <env:Value>_SOAP_FAULT_</env:Value>
         </env:Code>
         <env:Reason>
            <env:Text xml:lang="en">warning [2] curl_setopt() expects parameter 1 to be resource, null given,on line 815 in file C:\MAXXING\Apache\htdocs\MPCM\Web\api\ws\5.3\StoreServer.inc.php&lt;br /></env:Text>
         </env:Reason>
      </env:Fault>
   </env:Body>
</env:Envelope>

Open in new window




I'm going to open another question on this error...
gr8gonzo

Thank you for anotherguidance!!!
So that curlopt error is easy to fix. Your cURL connection handle is $curl, not $ch:

$curl = curl_init(...);

So change:
curl_setopt($ch, CURLOPT_POST, true);  // Deve ser POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $data1); // enviar o array

To:
curl_setopt($curl, CURLOPT_POST, true);  // Deve ser POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $data1); // enviar o array
Yes, thank you!

(What a distraction...)
After that I adjusted also

extension=php_sockets.dll

Open in new window


And it seens that curl is finally launching the API...
Great to hear!