having a problem finding this require_once - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: having a problem finding this require_once (/showthread.php?tid=81100) |
having a problem finding this require_once - richb201 - 01-24-2022 I have a lib that I am trying to require_once. This is the code in my app: require_once("../rst/RST/app/analytics/lib/Segment.php"); This returns an error Severity: Warning Message: require_once(../rst/RST/app/analytics/lib/Segment.php): failed to open stream: No such file or directory But when I go to the CLI and type ubuntu@ip-172-31-66-201:~/rst/RST$ ls app/analytics/lib/Segment.php app/analytics/lib/Segment.php It seems to be found. I any idea why I can require_once this file? BTW, I am using Docker and my Segment.php is on the server's drive, not on Docker. Could this be the issue? RE: having a problem finding this require_once - kenjis - 01-24-2022 Don't use "../" like relative path. The current directory may change at runtime. Use __DIR__ (the directory of the file) or other absolute paths like APPPATH. require_once(__DIR__ . "/../../rst/RST/app/analytics/lib/Segment.php"); RE: having a problem finding this require_once - richb201 - 01-25-2022 Thanks. The problem is that Composer didn't install it in my Controllers dir. Message: require_once(/app/application/controllers/../../rst/RST/app/analytics/lib/Segment.php): failed to open stream: No such file or directory It was put here: ubuntu@ip-172-31-66-201:~/rst/RST$ ls app/analytics/lib/Segment.php app/analytics/lib/Segment.php RE: having a problem finding this require_once - richb201 - 01-25-2022 I installed with Composer but that might be the issue. I can see it on the hard drive. But my code can't seem to see it. I don't know why? I then tried this: Message: require_once(/home/ubuntu/vendor/segmentio/analytics-php/lib/Segment.php): failed to open stream: No such file or directory But this also fails. RE: having a problem finding this require_once - kenjis - 01-25-2022 (01-25-2022, 07:10 AM)richb201 Wrote: Thanks. The problem is that Composer didn't install it in my Controllers dir. What do you mean "The problem is that Composer didn't install it in my Controllers dir."? Composer always installs package files in project_root/vendor/. And if you use Composer, you can use Composer autoloader, so you don't have to write require_once(). RE: having a problem finding this require_once - richb201 - 01-25-2022 Thanks. I do see a copy was installed under /vendor. Are you saying that if I am using autoloader(which I am), I don't need to require_once at all? If that is true, I might already be ok. Is there a way to confirm that Composer has installed it? RE: having a problem finding this require_once - kenjis - 01-25-2022 If you have project_root/vendor/autoload.php, you can use Composer autoloader. See https://codeigniter.com/user_guide/concepts/autoloader.html#composer-support RE: having a problem finding this require_once - richb201 - 01-26-2022 Thanks. I took a look at Composer/autokload_files.php and I see: return array( 'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php', '6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', '7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php', 'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php', '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', '9c67151ae59aff4788964ce8eb2a0f43' => $vendorDir . '/clue/stream-filter/src/functions_include.php', '8cff32064859f4559445b89279f3199c' => $vendorDir . '/php-http/message/src/filters.php', 'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php', '25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php', 'f598d06aa772fa33d905e87be6398fb1' => $vendorDir . '/symfony/polyfill-intl-idn/bootstrap.php', '0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php', 'b067bc7112e384b61c701452d53a14a8' => $vendorDir . '/mtdowling/jmespath.php/src/JmesPath.php', '8a9dc1de0ca7e01f3e08231539562f61' => $vendorDir . '/aws/aws-sdk-php/src/functions.php', '0b17741e1be8bc33be28693cd04d2893' => $vendorDir . '/koolreport/core/autoload.php', The problem is that MY /vendor/segmentio is under /home/ubuntu/vendor, while all the other vendors are under /app/vendor. So I think that my Composer installed my segentio in the wrong directory. Perhaps I ran Composer from the wrong directory? The vendor does have instructs to manually (w/o Composer) install their files. Perhaps I will try that instead. Can they both (composer install and manual install) can exist concurrently? I also see that the min php version for the Segment version I am using is 7.4 and my aws EC3 is using version 7.2. RE: having a problem finding this require_once - kenjis - 01-26-2022 > Perhaps I ran Composer from the wrong directory? Probably, yes. But if the library requires PHP 7.4 or later, and you are using PHP 7.2, you can't use the library. RE: having a problem finding this require_once - richb201 - 01-28-2022 Thanks. I think I got it going but the issue is php 7.2 vs php 7.4. Upgrading is no so easy due to my use of docker. I think the docker image needs to be rebuilt. |