PHP Uploading files using Azure Storage blob

Source: Internet
Author: User
Tags sql server express
This article mainly introduces about PHP using Azure Storage blob upload file, has a certain reference value, now share to everyone, the need for friends can refer to

Objective

Assigned to a project, a small station that requires content management, front-end page display and effects are done by front-end colleagues. I am responsible for setting up the content management background and providing the data interface. This project requires the management to be able to upload the video, but the server bandwidth provided by party A is very mini, and there are other projects in parallel on the same server.
To prevent the subsequent impact of a burst upgrade, the team leader recommended that I learn to use Azure Storage blobs and be ready to upgrade at any time.

PHP Version Limitations

The official SDK was found on GitHub.

Minimum Requirements

PHP 5.6 or above

Since the locally configured PHP environment is 5.5.12, the minimum PHP version required by the SDK is 5.6,composer blocking the update
Then use composer update --ignore-platform-reqs bypass demand to monitor the strong rise.
However, the class BlobResources.php sets the const to an array, which in 5.5 will error

Fatal Error:arrays is not allowed in class constants in E:\webroot\tp5cms\vendor\microsoft\azure-storage-blob\src\Blob \internal\blobresources.php on line 103

There is no way to upgrade PHP only.

Upgrade Wamp 2.5-3.1

For development needs, decide to upgrade Wampserver to the latest version.
Upgrade Wamp There is a trick: you can not directly overwrite the installation, you must first remove the old version and then install the new version.
Read the upgrade tips carefully.
A summary of what needs to be done is probably the following two things:

    • Removal service

      Start Wampserver
      "Important" Log in to MySQL to back up all database data
      Wampmanager-Stop All Services
      Remove Service---Wampmanager MySQL Services
      Remove service-----Apache----Wampmanager services
      Stop Wampmanager
      Right-click Wampmanager, Exit

    • Renaming a folder

      Name Wamp as a different name for backup

Installing the Storage Emulator

Since there is no Azure account for testing in the company, it is fortunate that Azure has a storage emulator for test development. Windows systems can be downloaded and installed directly, and Linux systems can use the open source storage simulator azurite.

    1. Download the simulator, here is the download link.

    2. Run StartStorageEmulator.cmd the discovery prompt after installation is complete SQL Server Express Local DB , there is a download link here. Select Express Edition, enter and select LocalDB to download and install.

    3. Run cmd again to find the error

C:\Program Files (x86) \microsoft Sdks\azure\storage Emulator>azurestorageemulator.exe Startwindows Azure Storage Emulator 5.3.0.0 Command line tool Unhandled exception: System.TimeoutException:Unable to open wait handle. In MICROSOFT.WINDOWSAZURE.S Torage. Emulator.Controller.EmulatorProcessController.InternalWaitForStorageEmulator (Int32 timeoutinmilliseconds) in Microsoft.WindowsAzure.Storage.Emulator.Controller.EmulatorProcessController.EnsureRunning (Int32 Timeoutinmilliseconds) in Microsoft.WindowsAzure.Storage.Emulator.Commands.StartCommand.RunCommand () in Microsoft.WindowsAzure.Storage.Emulator.Program.Main (string[] args)

After the query, it was found that there was a process that occupied port 10,000th.

#运行: >c:\users\walter>netstat-p Tcp-ano | findstr:10000> TCP 127.0.0.1:10000 0.0.0.0:0 LISTENING 2664 #根据PID 2664 queries the corresponding process >c:\users\walter>tasklist | Findstr "2664" >yundetectservice.exe 2664 Console 1 9,944 K #只是一个不重要的进程, remove and continue development >c:\users\walter>taskkill/pid 2664/f> success: The process of PID 2664 has been terminated. #以下是模拟器成功运行的范例 >c:\program Files (x86) \microsoft Sdks\azure\storage Emulator>azurestorageemulator.exe Startwindows Azure Storage Emulator 5.3.0.0 command line toolthe Storage Emulator was successfully started. >c:\program Files (x86) \microsoft Sdks\azure\storage Emulator>azurestorageemulator.exe StatusWindows Azure Storage Emulator 5.3.0.0 command line toolisrunning:trueblobendpoint:http://127.0.0.1:10000/queueendpoint:http:// 127.0.0.1:10001/tableendpoint:http://127.0.0.1:10002/

Start Development

The official example can be used to try new Container,blob and delete functions.
After the BLOB has been successfully uploaded, the resources in the storage emulator cannot be addressed.
eg. the account name used devstoreaccount1 , the container name created mycontainerudfpbk , and the Blob name 5ac1a5c82021d.png .
Depending on the rules in the document, the resource address should be
http://127.0.0.1:10000/devstoreaccount1/mycontainerudfpbk/5ac1a5c82021d.png
But the return data has always been

<Error> <Code>ResourceNotFound</Code> <Message> The specified resource does not exist. requestid:9d2d1b08-12b1-4feb-8636-4325eb71b838 time:2018-04-08t09:14:14.3007800z </Message></Error>

Based on reading the relevant articles, it is found that when you create a container, if you do not have access rights set (Container-level access policies), the default is to disallow external access.

ACL (publicaccesstype) permissions are divided into three, and CONTAINER_AND_BLOBS BLOBS_ONLY NONE , by default NONE .
If the resource needs to be accessible externally, set to BLOBS_ONLY .
Attach your own encapsulated Azure helper class

There is also a small problem in the middle, in the setting of authority, Aclbase reported a mistake
Static function MicrosoftAzure\Storage\Common\Internal\ACLBase::createAccessPolicy() should not be abstract
After querying, it is found that abstract and static are not allowed to be used on the method after PHP5.2.

#只要将ACLBase中的abstract protected static function Createaccesspolicy (); abstract protected static function Validateresourcetype ($resourceType); #改为protected static function Createaccesspolicy () {}protected static function Validateresourcetype ($resourceType) {} #即可

Summary

Three ways to abort a process

    1. Using PID to end a process
      taskkill /pid PID /f

    2. Using PID to end a process
      ntsd -c q -p PID

    3. End process with process name
      ntsd -c q -pn NAME.exe

Address

    1. An official SDK Address

    2. Personal Assistance class address

Note: Clarify the role of this process before forcing the end

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.